home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / DBio.more / old / USeqApp-aln.cp < prev    next >
Text File  |  1996-07-05  |  83KB  |  3,173 lines

  1. // USeqApp.aln.p -- alignment window/views 
  2. // d.g.gilbert, 1991 
  3.  
  4. /*
  5.         fix AlnPasteCommand so we don't cause bombs w/ paste + use of
  6.         uncommitted seqs (dispose?)
  7. */
  8.  
  9.  
  10. CONST
  11.     kAlnDocID == kAlnWindID;
  12.     kMinCommonPercent == 0.80;  //need user opt 
  13.  
  14.     kModifiedFlag == False; // temp until we figure out proper conditions for fSeq.modified 
  15.  
  16. VAR
  17.     integer        gMinCommonPercent; //??
  18.     TextStyle        gAlnTextStyle ;
  19.     longint        gMaxViewCellsBugFix;
  20.     Boolean        gMaxViewCellsBugSeen;
  21.     
  22. // TAlnSequence ------------------------
  23.  
  24. /*DEBUG AlnSeq edit display... 
  25.  
  26.     !problem of jumping up to vert=0 line seems to be color-related,
  27.     !problem of cursor/display frozen at horizontal=1 is related to long seqs > 1000...3000
  28. */
  29.  
  30. #pragma segment AOpen
  31. pascal void TAlnSequence::IAlnSequence(TSequence aSeq)
  32. VAR    aTextData: TTextData;
  33. {
  34.     fSeq= aSeq;
  35.     fFreeText= FALSE;   
  36.   fInset= gZeroVRect;   
  37.  
  38.     New(aTextData); 
  39.     FailNIL( aTextData);
  40.     aTextData->ITextData();
  41.     if ((aSeq!=NULL)) {
  42.         Handle(aTextData->fChars)= DisposeIfHandle(aTextData->fChars);
  43.         aTextData->fChars= aSeq->fBases;
  44.         }
  45.     fTextData= aTextData;
  46.     fSearchData.hTarget= NULL;
  47. }
  48.  
  49. pascal void TAlnSequence::ReplaceSeq(TSequence aSeq)
  50. {
  51.     fSeq= aSeq;
  52.     if ((fSeq!=NULL)) {
  53.         fTextData->fChars= fSeq->fBases;
  54.         StuffText( fSeq->fBases);
  55.         }
  56. }
  57.  
  58. #pragma segment AClose
  59. pascal void TAlnSequence::Free(void) // override 
  60. {
  61.     fTextData->fChars= NULL;
  62.     fTextData->Free();
  63.     fTextData= NULL;
  64.     fFreeText= FALSE;  
  65.     if ((fSearchData.hTarget!=NULL)) {
  66.         DisposHandle(Handle(fSearchData.hTarget));
  67.         fSearchData.hTarget= NULL;
  68.         }
  69.         
  70.     inherited::Free();       
  71. }
  72.  
  73.  
  74. pascal void TAlnSequence::DeInstall(void) 
  75. //unlink fSeq: TSequence from TTextView stuff
  76. //! must unlink seq from EditSeq or will dispose seq in next*2 install
  77. {
  78.     //- InstallSelection(TRUE, FALSE); -- not in Mapp3 ?! Need alternate?
  79.     fSeq= NULL;
  80.     fTextData->fChars= NULL;
  81.     StuffText(fSavedTEHandle);  
  82.     // ^^^^ this prevents sequences from Being Trashed !!!
  83. }
  84.  
  85.  
  86.  
  87.  
  88. #pragma segment ARes
  89. pascal void alnTEDrawHook(void)
  90. VAR
  91.     integer        indx, len; //must be, for regs?
  92.     integer        endx, i ;
  93.     char        ch, lastch;
  94.     CharsPtr        pText;
  95.  
  96.     longint        cw, pend, skip;
  97.     grafPtr        aPort;
  98.     pt    : point;
  99.     
  100.     procedure pushregs; inline 0x48E7,$FFF8;//movem.l d0-d7/a0-a4,-(sp)
  101.     procedure popregs;    inline 0x4CDF,$1FFF;//movem.l (sp)+,d0-d7/a0-a4
  102.     procedure getD0D1A0( integer var d0, d1, CharsPtr var a0) inline
  103.         0x225F,    //move.l  (a7)+, a1
  104.         0x2288,    /*move.l    a0, (a1)*/         
  105.         0x225F,    //move.l  (a7)+, a1
  106.         0x3281,    /*move.w    d1, (a1)*/       
  107.         0x225F,    //move.l  (a7)+, a1
  108.         0x3280();    /*move.w    d0, (a1)*/         
  109.  
  110.     //-- test if rgbcolor is time dragger.. only Partly...
  111.     /*! looks like Indx == LineStart and Len == lineLen even
  112.          when only a small portion of line is drawn !
  113.          -- try calc TRUE indx for visible text
  114.          from destrect-viewrect ???
  115.         ---*/
  116. {
  117.     pushregs(); //-- ? not needed
  118.     getD0D1A0( indx, len, pText);
  119.     
  120.     //this helps!
  121.     cw= gAlnCharWidth;
  122.     getpen( pt);
  123.     if pt.h < 0 then {
  124.         skip= (-pt.h) / cw;
  125.       indx= indx + skip;
  126.         len= len - skip;
  127.         move( skip*cw, 0);
  128.         }
  129.         
  130.     pend= len * cw; //<<! integer overflow w/ len ~> 3000 ??
  131.     GetPort(aPort);
  132.     if pend > aPort->portRect.right then {
  133.         skip= (pend - aPort->portRect.right) / cw;
  134.         len= len - skip;
  135.         }
  136.             
  137.     endx= indx + len - 1;
  138.     lastch= ((char)(0));
  139.     for indx= indx to endx do {
  140.         ch= (*pText)[indx];
  141.         if (ch!=lastch) then
  142.          case ch of
  143.             'A','a': RGBForeColor( gAcolor);
  144.             'C','c': RGBForeColor( gCcolor);
  145.             'G','g': RGBForeColor( gGcolor);
  146.             'T','t',
  147.             'U','u': RGBForeColor( gTcolor);
  148.             otherwise
  149.                              RGBForeColor( gNcolor);
  150.             }
  151.      DrawChar(ch);
  152.      lastch= ch;
  153.     //_ if (indx mod 10 == 9) then DrawChar(' '); *//*spacer ??
  154.      }
  155.      
  156.     popregs();
  157. } //alnTEDrawHook
  158.  
  159.  
  160.  
  161. pascal void TAlnSequence::MakeTERecord(void) // override 
  162. VAR  
  163.     procPtr        mydraw, mydrawstripped, addr;
  164. {
  165.     inherited::MakeTERecord();
  166.     
  167.     mydraw= &alnTEDrawHook;  // debug this, are we getting right address here !?
  168.     mydrawstripped= procPtr(StripLong(mydraw));
  169.     addr= mydrawstripped;
  170.  
  171.     //- TECustomHook(intDrawHook, addr, fHTE);
  172.     gDefTEDrawHook= addr;     //save default
  173.  
  174.     //!? is alnTEDrawHook bad in mapp3 YES YEYEYEYEYEYEGGEYEGEGEGEG?!?!>?!?!?!?!?>?!
  175.  /*     if (True) { */
  176.   if (!gConfiguration.hasColorQD) {   
  177.         addr= gDefTEDrawHook;
  178.         //- TECustomHook( intDrawHook, addr, fHTE); 
  179.         }
  180. }
  181.  
  182.  
  183. #pragma segment AOpen
  184. pascal void TAlnSequence::ShowReverted(void) /* override */ 
  185. {
  186.     inherited::ShowReverted();
  187. }
  188.         
  189.         
  190. pascal TAlnSequence::HandleMouseDown( VPoint theMouse, TToolboxEvent event, 
  191.                              hysteresis: Point):Boolean; // override 
  192. VAR  theTarget: TView; //?
  193. {        
  194.     theTarget= TView(GetWindow->fTarget); 
  195.     if (theTarget != this) if (BecomeTarget); //GetWindow->SetTarget(this); 
  196.   HandleMouseDown= inherited::HandleMouseDown(theMouse,event,hysteresis);
  197. }
  198.         
  199.     
  200. pascal void TAlnSequence::DoKeyEvent( TToolboxEvent event) // override 
  201. /*! Intercept upArrow, downArrow, return, enter, tab keys:
  202.     up/downarrow -> move this up/down in alnView
  203.     return -> move this down (& to left margin?) in alnView
  204.     enter  -> ?
  205.     tab    -> ?
  206.     chClear chDown chEnd    chHome chEnter chEscape
  207.     chHelp chLeft chPageDown chPageUp
  208.     chReturn chRight chTab chUp
  209.     --------*/
  210. CONST
  211.     down1     ==  1;
  212.     up1            == -1;
  213.     downPage     ==  10;  // this is arbitrary...
  214.     upPage        == -10;
  215.     toBottom=  25000;
  216.     toTop        == -25000;
  217.     
  218.     procedure vertMove(integer nrows) // +/- nrows
  219.     integer        var  aRow, aCol;
  220.     {
  221.         aRow= MinMax( 1, TAlnView(fSuperView).fEditRow + nrows, 
  222.                                             TAlnView(fSuperView).fNumOfRows);
  223.         aCol= (*fHTE)->selStart;
  224.         TAlnView(fSuperView)->InstallEditSeq(aRow, aCol, aCol, kHighlight);
  225.     }
  226.         
  227. {
  228.     if (Focus) ; //? fix for misplaced drawing when typing ???
  229.     
  230.     CASE event->fCharacter OF
  231.         /*----
  232.         case chEscape:
  233.             if (event->fKeycode == kClearVirtualCode) ...
  234.             else ...;
  235.         -----*/
  236.         
  237.         chTab: ;
  238.           //? do horizontal shift here ?
  239.             /*---
  240.             if event.IsShiftKeyPressed then vertMove(up1)
  241.             else vertMove(down1);
  242.             -----*/
  243.             
  244.         case chRight:
  245.             if event.IsShiftKeyPressed then 
  246.             else inherited::DoKeyEvent(event);
  247.         case chLeft:
  248.             if event.IsShiftKeyPressed then 
  249.             else inherited::DoKeyEvent(event);
  250.             
  251.         case chUp:
  252.             if event.IsShiftKeyPressed then vertMove(toTop)
  253.             else vertMove(up1);
  254.             
  255.         chDown,
  256.         chEnter, chReturn:
  257.             if event.IsShiftKeyPressed then vertMove(toBottom)
  258.             else vertMove(down1);
  259.             
  260.         chPageDown    :    vertMove( downPage); 
  261.         chPageUp        :    vertMove( upPage);
  262.         chHome            : vertMove( toTop);
  263.         chEnd                 : vertMove( toBottom);
  264.             
  265.         default: 
  266.             inherited::DoKeyEvent(event);
  267.             
  268.         }
  269.     
  270.     if (( kModifiedFlag /*???? aCommand != gNoChanges*/) && (fSeq!=NULL) then begin
  271.         fSeq.modified; 
  272.         }
  273. }
  274.  
  275. pascal void TAlnSequence::DoMenuCommand(aCommandNumber:CommandNumber); // override 
  276. {
  277.     inherited::DoMenuCommand(aCommandNumber);
  278.     if ( kModifiedFlag /*????aCommand != gNoChanges*/) && (fSeq!=NULL) then begin
  279.         fSeq.modified; 
  280.         end();
  281. }
  282.  
  283. pascal void TAlnSequence::DoMouseCommand(VPoint VAR theMouse, TToolboxEvent event,
  284.                                                Point hysteresis) // override 
  285. {
  286.     inherited::DoMouseCommand(theMouse,event,hysteresis);
  287.     if ( kModifiedFlag /*????aCommand != gNoChanges*/) && (fSeq!=NULL) then begin
  288.         fSeq.modified; 
  289.         end();
  290. }
  291.  
  292. pascal TTETypingCommand TAlnSequence::DoMakeTypingCommand(Char ch) // override 
  293. VAR  aAlnseqTypingCommand:     TAlnseqTypingCommand;
  294. {
  295.     if (Focus) ; //? fix for misplaced drawing when typing ???
  296.     New(aAlnseqTypingCommand);
  297.     FailNIL(aAlnseqTypingCommand);
  298.     aAlnseqTypingCommand->ITETypingCommand(this, ch);
  299.     DoMakeTypingCommand = aAlnseqTypingCommand;
  300. }
  301.  
  302. pascal void TAlnseqTypingCommand::DoNormalChar( Char aChar) // override 
  303. VAR  aSeq: TSequence;
  304.         TAlnView        aAlnView;
  305. {
  306.     inherited::DoNormalChar( aChar);
  307.     aAlnView= TAlnView(TAlnSequence(fTEView).fSuperView);
  308.     aSeq= TAlnSequence(fTEView).fSeq;
  309.     aAlnView->UpdateWidth(aSeq);
  310.     if (TAlnSequence(fTEView).Focus) ; //? fix for misplaced drawing when typing ???
  311.  
  312.         //? fix for integer overflow.... 
  313.     /*---  no good...
  314.     WITH TAlnSequence(fTEView).(*fHTE)^){
  315.         if ((destRect.right < 0)) destRect.right= 20000;
  316.         if ((viewRect.right < 0)) viewRect.right= 20000;
  317.         }
  318.     ----*/
  319. }
  320.  
  321.  
  322.  
  323.  
  324.  
  325. // TAlnView ------------------------
  326.  
  327.                 
  328. #pragma segment TAlnView
  329.     
  330.     
  331. pascal void TAlnView::IAlnView( TAlnDoc itsDocument, TSeqList aSeqList)
  332. VAR  
  333.         VRect        vbounds;
  334. {
  335.     fAlnDoc= itsDocument;
  336.     fAlnList= aSeqList;
  337.     fLocked= FALSE;
  338.     
  339.     DelColLast( fNumOfCols);   //fix for prefsave...
  340.     fRowheight= GetRowHeight(1);
  341.     DelRowLast( fNumOfRows);  
  342.     RowToVRect( 1, 1, vbounds); 
  343.     gAlnTextStyle= gAlnStyle; //temp
  344.     fEditSeq= NULL;
  345.     
  346.     fEditSeq = TAlnSequence(
  347.                     gViewServer->DoCreateViews(fDocument, this, kAlnTEViewID, vbounds.topleft));
  348.     FailNIL(fEditSeq);
  349.     fEditSeq->IAlnSequence(NULL);  //must be NULL or 1st seq gets trashed...
  350.     fEditRow= 0; 
  351.     RemoveSubView(fEditSeq);
  352.     gAlnTextStyle= fEditSeq->fTextStyle;
  353.  
  354.     /*-- SetPortTextStyle(gAlnTextStyle);  << THIS BOMBS PROG, no window here... */ 
  355.     gAlnCharWidth= CharWidth('G');   
  356.     gMaxViewCellsBugFix= kMaxCoord / (gAlnCharWidth+4);
  357.     gMaxViewCellsBugSeen= false;
  358. }
  359.  
  360.  
  361. pascal void TAlnView::UpdateSize(void)
  362. VAR      diff: longint;
  363. {
  364.     if ((fAlnList!=NULL)) {
  365.         diff= fAlnList.GetSize - fNumOfRows;
  366.         if ((diff>0)) InsRowLast( 1, fRowheight)     
  367.         else if ((diff<0)) DelRowLast( -diff);
  368.         }    else
  369.         DelRowLast( fNumOfRows);
  370. }
  371.  
  372.  
  373. pascal void TAlnView::UpdateWidth(TSequence aSeq)
  374. VAR            alnlen : longint;
  375.               TScroller        aScroll;
  376. {
  377.     alnlen= GetHandleSize(aSeq->fBases) + 30;
  378. //+?!?? trying to find bug which mangles view when > ~2000 bases 
  379.     if (alnlen>gMaxViewCellsBugFix) then gMaxViewCellsBugSeen= true;
  380.     alnlen= Min( gMaxViewCellsBugFix, alnlen); 
  381.     if alnlen > fNumOfCols then InsColLast( alnlen-fNumOfCols, gAlnCharWidth);  
  382.     SetColWidth(1, fNumOfCols, gAlnCharWidth);  
  383.     if (fAlnDoc!=NULL) && (fAlnDoc->fAlnHIndex!=NULL))
  384.         fAlnDoc->fAlnHIndex->UpdateWidth(); //keep ruler in sync
  385. }
  386.  
  387. pascal void TAlnView::UpdateAllWidths(void)
  388. VAR            alnlen : longint;
  389.               TScroller        aScroll;
  390.         pascal void findMaxLength( TSequence aSeq)
  391.         {
  392.             alnlen= Max( alnlen, GetHandleSize(aSeq->fBases));
  393. //+?!?? trying to find bug which mangles view when > ~2000 bases 
  394.             if (alnlen>gMaxViewCellsBugFix) then gMaxViewCellsBugSeen= true;
  395.             alnlen= Min( gMaxViewCellsBugFix, alnlen); 
  396.         }
  397. {
  398.     alnlen= 0;
  399.     fAlnList->Each( findMaxLength);
  400.     alnlen= alnlen + 30; 
  401.     if alnlen > fNumOfCols then InsColLast( alnlen-fNumOfCols, gAlnCharWidth);  
  402.     SetColWidth(1, fNumOfCols, gAlnCharWidth);  
  403.     if (fAlnDoc!=NULL) && (fAlnDoc->fAlnHIndex!=NULL))
  404.         fAlnDoc->fAlnHIndex->UpdateWidth(); //keep ruler in sync
  405. }
  406.  
  407.  
  408. pascal void TAlnView::DeInstallEditSeq(void)
  409. VAR      lastCmd    : TCommand;
  410.             VRect        vbounds;
  411. {
  412.     if ((fEditRow!=0)) { 
  413.       // uninstall old editrow 
  414.         // Commit the last command to prevent undo from applying to the wrong edit text 
  415.         lastCmd= gApplication->GetLastCommand();
  416.         if ((lastCmd != NULL) && (lastCmd->fContext == fEditSeq))
  417.             gApplication->CommitLastCommand();
  418.         UpdateWidth(fEditSeq->fSeq);
  419.         fEditSeq->DeInstall();            
  420.         RemoveSubView(fEditSeq);
  421.  
  422.         if (TAlnDoc(GetWindow->fDocument).fUseColor) {
  423.             //Partial fix for lack of TEDrawHook...
  424.             RowToVRect( fEditRow, 1, vbounds);
  425.             InvalidateVRect( vbounds);
  426.             }
  427.             
  428.         fEditRow= 0;
  429.         }
  430. }
  431.  
  432.  
  433. pascal void TAlnView::InstallEditSeq(integer row, selStart,selEnd, boolean doLight)
  434. VAR
  435.     VRect        vbounds ;
  436.     Rect        qdbounds;
  437.     aSeq        : TSequence;
  438.     aCell        : GridCell;
  439.     vp            : Vpoint;
  440. {
  441.     DeInstallEditSeq();
  442.  
  443.     fEditRow= row;
  444.     if ((row != 0)) {
  445.         aSeq= TSequence(fAlnList->At( row));
  446.         RowToVRect( row, 1, vbounds);
  447.         //- ViewToQDRect( vbounds, qdbounds); *//*???
  448.         
  449.         AddSubView( fEditSeq);  //?! must do before locate/resize so suview is set
  450.        if (fEditSeq->Focus()) ; //??
  451.  
  452.         fEditSeq->ReplaceSeq( aSeq);
  453.  
  454.         WITH vbounds){ //was qdbounds
  455.             SetVpt( vp, left, top);
  456.             fEditSeq->Locate( vp, kDontRedraw);
  457.             SetVpt( vp, right-left,bottom-top);
  458.             fEditSeq->Resize( vp, kDontRedraw);
  459.             }
  460.             
  461.         SetSelect( selStart, selEnd, fEditSeq->fHTE);  
  462.         if (doLight) {
  463.             aCell.h= selStart+1; 
  464.             aCell.v= row;
  465.           SelectCell( aCell, FALSE, TRUE, TRUE);
  466.             ScrollSelectionIntoView( TRUE); //< redraw does highlight !
  467.           SelectCell( aCell, FALSE, TRUE, FALSE); //turn off highlight
  468.  
  469.             //- fEditSeq->InstallSelection(FALSE, TRUE);
  470.             //- TESetSelect( selStart, selEnd, fEditSeq->fHTE);
  471.             }
  472.     
  473.         if (fEditSeq->BecomeTarget()) ; // GetWindow->SetTarget(fEditSeq); 
  474.         }
  475. }
  476.  
  477. pascal void TAlnView::registerInsertLast( TSequence aSeq)
  478. {
  479.     InsRowLast( 1, fRowheight);    
  480.     UpdateWidth(aSeq);    
  481. }
  482.  
  483. pascal void TAlnView::addToAlnList( TSequence aSeq)
  484. VAR  aRect: VRect;
  485. {
  486.     fAlnList->InsertLast( aSeq);
  487.     //-- registerInsertLast( aSeq); 
  488.     InsRowLast( 1, fRowheight);    
  489.     UpdateWidth( aSeq);    
  490.     /*-- // insrowlast does this inval....
  491.     RowToVRect( fNumOfRows, 1, aRect);
  492.     InvalidateVRect( aRect); 
  493.     ----*/
  494. }
  495.  
  496. pascal TSequence TAlnView::SeqAt( integer aRow)  
  497. {
  498.     SeqAt= TSequence(fAlnList->At( aRow));  
  499. }
  500.  
  501.  
  502. pascal void TAlnView::MakeConsensus(void)
  503. VAR
  504.     arow    : integer;
  505.     arect    : VRect;
  506. {
  507.     fAlnList->MakeConsensus();
  508.     arow= fAlnList->ConsensusRow();
  509.     if ((arow>0)) {
  510.         RowToVRect( arow, 1, aRect);
  511.         InvalidateVRect( aRect);
  512.         }
  513. }
  514.  
  515.  
  516. pascal charsHandle TAlnView::FindCommonBases( integer minCommonPerCent)
  517. VAR  hFirst: CharsHandle;
  518. {
  519.     gMinCommonPercent= minCommonPerCent;
  520.     FindCommonBases= fAlnList->FindCommonBases(minCommonPercent, hFirst);
  521.     Handle(hFirst)= DisposeIfHandle( hFirst);
  522. }
  523.  
  524.  
  525. pascal void TAlnView::Close(void) /* override */ 
  526. {
  527.         DeInstallEditSeq();
  528.         inherited::Close();
  529. }
  530.  
  531. pascal void TAlnView::HiliteCommonBases(void)
  532. var  
  533.     TSequence        cons;
  534.     CharsHandle        hCon, hSeq, hFirst;
  535.     longint        len, maxlen, conlen, ibase;
  536.     arow    : integer;
  537.     integer        nseq ;
  538.     CharsHandle        hMaxbase;
  539.     
  540.         procedure markCommon(TSequence aSeq)
  541.         integer        var ibase;
  542.                 char        ch;
  543.                 gridCell        aCell;
  544.         {
  545.             nseq= nseq+1;
  546.             if !(aSeq.isConsensus || (aSeq->fKind=kOtherSeq)) then begin
  547.                 handle(hSeq)= aSeq->fBases;
  548.                 //- len= GetHandleSize(Handle(hSeq));
  549.                 for ibase= 0 to maxlen-1 do  
  550.                  if (UprChar((*hSeq)^[ibase]) == (*hMaxbase)^[ibase]) then begin
  551.                   aCell.h= ibase+1;
  552.                   aCell.v= nseq;
  553.                   this->SelectCell( aCell, TRUE, !kHighlight, TRUE);
  554.                     }
  555.                 }
  556.         }
  557.         
  558. {
  559.     cons= fAlnList->Consensus();
  560.     if ((cons=NULL)) cons= TSequence(fAlnList->First());
  561.  
  562.     if ((cons!=NULL)) {
  563.         arow= fAlnList->GetIdentityItemNo( cons);
  564.         handle(hCon)= cons->fBases;   
  565.         
  566.         hMaxBase= fAlnList->FindCommonBases(gMinCommonPercent, hFirst); 
  567.         
  568.         maxlen= GetHandleSize(handle(hMaxBase));
  569.         this->InvalidateSelection();
  570.         this->SetEmptySelection( !kHighlight);        
  571.         nseq= 0;
  572.         fAlnList->Each( markCommon);
  573.         this->InvalidateSelection();
  574.         DisposHandle(    handle(hMaxBase)); 
  575.         DisposHandle(    handle(hFirst)); 
  576.         }
  577. }
  578.  
  579.  
  580.  
  581. #pragma segment ARes
  582.  
  583. pascal void TAlnView::Free(void) // override 
  584. VAR     itsEditSeq: TAlnSequence;
  585. {
  586.     FreeData();
  587.     fAlnList= NULL; //! fAlnList == fSeqList is owned by Doc !
  588.     
  589.     itsEditSeq= fEditSeq;     
  590.     if ((itsEditSeq != NULL) && (itsEditSeq->fSuperView != NULL))
  591.         itsEditSeq->fSuperView->RemoveSubView(itsEditSeq);
  592.  
  593.     inherited::Free();
  594.     TObject(itsEditSeq)= FreeIfObject(itsEditSeq);                     
  595. }
  596.  
  597. pascal void TAlnView::FreeData(void)
  598. {
  599.     //!! TAlnView doesn't own fAlnList data ! is just ptr to fDoc->fSeqList 
  600. }
  601.  
  602.  
  603. /************
  604. procedure myDrawAln( charsPtr pText, integer indx, len)
  605. var
  606.     integer        endx, i ;
  607.     ch    : char;
  608.  
  609.     integer        cw, pend, skip;
  610.     grafPtr        aPort;
  611.     pt    : point;
  612. {
  613.     cw= gAlnCharWidth;
  614.     getpen( pt);
  615.     if pt.h < 0 then begin
  616.         skip= (-pt.h) / cw;
  617.       indx= indx + skip;
  618.         len= len - skip;
  619.         move( skip*cw, 0);
  620.         end();
  621.     pend= len * cw;
  622.     GetPort(aPort);
  623.     if pend > aPort->portRect.right then begin
  624.         skip= (pend - aPort->portRect.right) / cw;
  625.         len= len - skip;
  626.         end();
  627.             
  628.     endx= indx + len - 1;
  629.     for i= indx to endx do begin
  630.         ch= (*pText)[i];
  631.         case ch of
  632.             'A','a': RGBForeColor( gAcolor);
  633.             'C','c': RGBForeColor( gCcolor);
  634.             'G','g': RGBForeColor( gGcolor);
  635.             'T','t',
  636.             'U','u': RGBForeColor( gTcolor);
  637.             otherwise
  638.                              RGBForeColor( gNcolor);
  639.             end();
  640.      DrawChar(ch);
  641.     //_ if (indx mod 10 == 9) then DrawChar(' '); *//*spacer ??
  642.      end();
  643. end; //myDrawAln
  644. *******/
  645.  
  646.  
  647. pascal void DrawAlnColors(colorsArray VAR colors, Boolean swapBackColor,
  648.                                 charsPtr        pText; integer indx, len)
  649. VAR
  650.     longint        endx, i ;
  651.     ch, lastch    : char;
  652.     longint        cw, pend, skip;
  653.     grafPtr        aPort;
  654.     pt    : point;
  655. {
  656.     cw= gAlnCharWidth;
  657.     getpen( pt);
  658.     if (pt.h < 0) {
  659.         skip= (-pt.h) / cw;
  660.       indx= indx + skip;
  661.         len= len - skip;
  662.         move( skip*cw, 0);
  663.         }
  664.     pend= len * cw;
  665.     GetPort(aPort);
  666.     if (pend > aPort->portRect.right) {
  667.         skip= (pend - aPort->portRect.right) / cw;
  668.         len= len - skip;
  669.         }
  670.             
  671.     endx= indx + len - 1;
  672.     /*-- backcolor not showing -- need erase or something...
  673.     if ((swapBackcolor)) RGBForeColor( colors[' '])
  674.     else RGBBackColor( colors[' ']);
  675.     ---*/
  676.     
  677.     lastch= ((char)(0));
  678.     FOR i= indx to endx do {
  679.         ch= (*pText)[i];
  680.         /*- if ((swapBackcolor)) RGBBackColor( colors[ch])
  681.         else */
  682.         if ((ch!=lastch)) RGBForeColor( colors[ch]);
  683.         DrawChar(ch);
  684.         lastch= ch;
  685.         }
  686.  
  687.  
  688.  
  689. pascal void TAlnView::DrawCell(aCell:GridCell; VRect aRect)
  690.             // override 
  691. VAR
  692.         TAlnSequence        aSeq;
  693.         Handle        hText;
  694.         longint        len ;
  695.         TextStyle        aTextStyle;
  696. {
  697. /*----
  698.   if (fAlnList!=NULL) && (aCell.v <= fAlnList->fSize) then begin
  699.         aSeq= TAlnSequence(fAlnList->at(aCell.v));
  700.         if aSeq!=NULL then begin
  701.             aTextStyle = aSeq->fTextStyle;
  702.             SetPortTextStyle(aTextStyle);
  703.         
  704.             moveto( aRect.left, aRect.bottom-4);  
  705.             hText= aSeq->fSeq.fBases;
  706.             len= GetHandleSize(hText);
  707.             HLock(hText);
  708.             myDrawAln( charsPtr((*hText)), 0, len);
  709.             HUnlock(hText);
  710.             end();
  711.         end();
  712. -------*/
  713. }
  714.  
  715.  
  716.  
  717. //+?!?? trying to find bug which mangles view when > ~2000 bases 
  718. pascal void TAlnView::CellToVRect( GridCell aCell, VRect VAR aRect) // override 
  719. VAR
  720.          longint        width; //! these where shorts 
  721.         longint        height;
  722. {
  723.     inherited::CellToVRect( aCell, aRect);
  724. /***
  725.     if ((aCell.h < 1) || (aCell.v < 1) 
  726.     || (aCell.h > fNumOfCols) || (aCell.v > fNumOfRows))) 
  727.         aRect= gZeroVRect 
  728.     else {                             
  729.         width= fColWidths->GetValue(aCell.h);
  730.         aRect.left= width * (aCell.h - 1);
  731.         /*+ if (fColWidths->fNoOfChunks == 1) then  
  732.             aRect.left= width * (aCell.h - 1) 
  733.         else
  734.          aRect.left= fColWidths->SumValues(1, aCell.h - 1);
  735.         */
  736.  
  737.         aRect.right= aRect.left + width;
  738.  
  739.         height= fRowHeights->GetValue(aCell.v);
  740.         if (fRowHeights->fNoOfChunks == 1) then
  741.             aRect.top= height * (aCell.v - 1) 
  742.         else
  743.             aRect.top= fRowHeights->SumValues(1, aCell.v - 1);
  744.         aRect.bottom= aRect.top + height;
  745.         }
  746. ***/
  747. }
  748.  
  749. //+?!?? trying to find bug which mangles view when > ~2000 bases 
  750. pascal TAlnView::VPointToLastCell( aPoint: VPoint):GridCell; // override 
  751. VAR  aCell: GridCell;  longint lwidth,
  752. {
  753.     VPointToLastCell= inherited::VPointToLastCell( aPoint);
  754. /***
  755.     //+ aCell.h= fColWidths->FindItem(aPoint.h);
  756.     aCell.h= 0;
  757.     if ((aPoint.h >= 0) && (aPoint.h <= fColWidths->fTotal))) {
  758.             if (fColWidths.(*fChunks)^[0].value > 0)) {
  759.                 lwidth= 1 +  (aPoint.h - 1) / fColWidths.(*fChunks)^[0].value;
  760.                 lwidth= Min( lwidth, fColWidths->fNoOfItems); 
  761.                 if (lwidth>Maxint) then aCell.h= Maxint
  762.                 else aCell.h= lwidth;
  763.                 }            }        else if (aPoint.h == 0) then
  764.             aCell.h= 1;
  765.     
  766.     if (aCell.h == 0) then aCell.h= fNumOfCols;
  767.  
  768.     aCell.v= fRowHeights->FindItem(aPoint.v);
  769.     if (aCell.v == 0) then aCell.v= fNumOfRows;
  770.  
  771.     VPointToLastCell= aCell;
  772. ***/
  773. }
  774.  
  775. //+?!?? trying to find bug which mangles view when > ~2000 bases 
  776. pascal Boolean TAlnView::Focus(void) // override 
  777. VAR
  778.          Point        aPt, bPt, deltaOrigin;
  779.          Rect        visQDRect;
  780.          
  781. {
  782.     Focus= inherited::Focus;
  783. /****
  784.     if (this->IsFocused()))    
  785.         Focus= TRUE 
  786.  
  787.     else if (this->FocusOnSuperView())) {
  788.          //? don't do it -- use superview focus here ?!?!?
  789.  
  790.         SetOrigin(fQDOrigin.h, fQDOrigin.v);     
  791.         if ((gCurrPrintHandler != NULL) && (gCurrPrintHandler->fView == this))) {
  792.             //- deltaOrigin= fQDOrigin - gCurrPrintHandler.GetQDOrigin
  793.             aPt= fQDOrigin;
  794.             bPt= gCurrPrintHandler->GetQDOrigin();
  795.             SubPt( bPt, aPt);
  796.             deltaOrigin= bPt;
  797.             }        else if (fSuperView!=NULL)) {
  798.             //- deltaOrigin= fQDOrigin - fSuperView->fQDOrigin
  799.             aPt= fQDOrigin;
  800.             bPt= fSuperView->fQDOrigin;
  801.             SubPt( bPt, aPt);
  802.             deltaOrigin= bPt;
  803.             }        else
  804.             deltaOrigin= gZeroPt;
  805.  
  806.         gFocusedView= this;        // Now we have the basic focus 
  807.  
  808.         //- // Add the clipping 
  809.         /*--
  810.         this->GetVisibleQDRect(visQDRect);
  811.         this->OffsetAndClipFurtherTo(visQDRect, deltaOrigin);
  812.          ---*/
  813.      
  814.         Focus= TRUE;
  815.         }    else     
  816.         Focus= FALSE;
  817. ***/
  818. }
  819.  
  820. //+?!?? trying to find bug which mangles view when > ~2000 bases 
  821. pascal void TAlnView::UpdateCoordinates(void) // override 
  822. CONST  kMaxOriginFixup == 16000; //was 1024; // The maximum amount by which to _fixup_
  823. VAR
  824.          VPoint        localOriginInSuper, aVpt;
  825.          VPoint        actualViewToQDOffset;
  826.          VRect        itsExtent, aVRect;
  827.          Point        deltaOrigin, aPt; 
  828.          VRect        itsFrame, visibleExtent;
  829. {
  830.     inherited::UpdateCoordinates();
  831. /***
  832.     this->GetLocalOffsetInSuper(localOriginInSuper);
  833.  
  834.     if (gCurrPrintHandler!=NULL) && (gCurrPrintHandler->fView == this)
  835. ) {
  836.         gCurrPrintHandler->GetViewToQDOffset(actualViewToQDOffset);
  837.         /*- actualViewToQDOffset = actualViewToQDOffset + 
  838.             VPoint(gCurrPrintHandler->GetQDOrigin()); */
  839.         PtToVPt(gCurrPrintHandler->GetQDOrigin(), aVpt);
  840.         AddVPt(aVpt, actualViewToQDOffset);
  841.         }    else {
  842.         /*- actualViewToQDOffset = fSuperView->fViewToQDOffset + VPoint(fSuperView->fQDOrigin) 
  843.                         - localOriginInSuper;*/
  844.         PtToVPt(fSuperView->fQDOrigin, actualViewToQDOffset);
  845.         aVPt= fSuperView->fViewToQDOffset;
  846.         AddVPt(aVPt, actualViewToQDOffset);
  847.         SubVPt(localOriginInSuper, actualViewToQDOffset);
  848.         }            
  849.         
  850.     fViewToQDOffset= actualViewToQDOffset;     
  851.     this->GetExtent(itsExtent);
  852.     //- if (VRect(-kMaxCoord,-kMaxCoord, kMaxCoord, kMaxCoord)->Contains(itsExtent))
  853.     if (itsExtent.left >= -kMaxCoord) && (itsExtent.right <= kMaxCoord)
  854.         && (itsExtent.top <= -kMaxCoord) && (itsExtent.bottom <= kMaxCoord)
  855. ) {
  856.         //-fQDOrigin= actualViewToQDOffset->ToPoint();
  857.         aPt= fQDOrigin;
  858.         SetPt( aPt, actualViewToQDOffset.h, actualViewToQDOffset.v);
  859.         fViewToQDOffset= gZeroVPt;
  860.         }    else {
  861.         SetPt( deltaOrigin, 
  862.                     (actualViewToQDOffset.h % kMaxOriginFixup), 
  863.                     (actualViewToQDOffset.v % kMaxOriginFixup) );
  864.         //- fViewToQDOffset= actualViewToQDOffset - VPoint(deltaOrigin);
  865.         PtToVPt( deltaOrigin, aVpt);
  866.         fViewToQDOffset= VPtSubVPt( actualViewToQDOffset, aVPt);
  867.         fQDOrigin= deltaOrigin;
  868.         }
  869.  
  870.     if ((gDrawingPictScrapView == this) || ((gCurrPrintHandler != NULL) && (gCurrPrintHandler->fView == this)))
  871. ) {
  872.         this->GetExtent(itsExtent);
  873.         fVisibleExtent= itsExtent;
  874.         }    else {
  875.         this->GetFrame(itsFrame);
  876.         //- visibleExtent= itsFrame && fSuperView->fVisibleExtent;
  877.         aVrect= fSuperView->fVisibleExtent;
  878.         if (SectVRect(itsFrame, aVrect, visibleExtent)) ;
  879.         this->SuperToLocalVRect(visibleExtent);
  880.         fVisibleExtent= visibleExtent;
  881.         }
  882. *****/        
  883. }
  884.  
  885.  
  886. //+?!?? trying to find bug which mangles view when > ~2000 bases 
  887. pascal void TAlnView::Draw(VRect area) /* override */ 
  888. VAR
  889.     VRect        aRect, bRect;
  890.     GridCell        startCell, stopCell, startCellToDraw;
  891.     VRect        cellsArea, localArea;
  892. {
  893.     inherited::Draw( area);
  894. /*****
  895.     if ((fNumOfRows > 0) && (fNumOfCols > 0))) {
  896.  
  897.         startCell= this->VPointToLastCell(area.topLeft);
  898.         stopCell = this->VPointToLastCell(area.botRight);
  899.  
  900.         this->CellToVRect(startCell, aRect);
  901.         this->CellToVRect(stopCell, bRect);
  902.         bRect.top= aRect.top; 
  903.         bRect.left= aRect.left; //[topLeft]= aRect[topLeft];
  904.         localArea= bRect;
  905.  
  906.         startCellToDraw= startCell;
  907.         cellsArea= localArea;
  908.         if (area.top >= aRect.bottom - (fRowInset / 2))) {
  909.             startCellToDraw.v= startCellToDraw.v + 1;
  910.             cellsArea.top=  cellsArea.top + (aRect.bottom - aRect.top); //GetLength(vSel);
  911.             }
  912.  
  913.         this->DrawRangeOfCells(startCellToDraw, stopCell, cellsArea);
  914.         }
  915. ****/
  916. }
  917.  
  918.  
  919.  
  920.  
  921. pascal void TAlnView::DrawRangeOfCells(GridCell startCell, stopCell, VRect aRect) 
  922.                                         // override */ /*from TGridView method
  923. VAR
  924.     colWidth, rowHeight, qdleft    : longint;
  925.     vleft            : longint;
  926.   TextStyle        aTextStyle;
  927.     Rect        aQDRect;
  928.  
  929.     function showA( c: char): char;
  930.     begin     if (c='A') || (c='a') then showA= c else showA= ' ';
  931.     end();
  932.     function showC( c: char): char;
  933.     begin     if (c='C') || (c='c') then showC= c else showC= ' ';
  934.     end();
  935.     function showG( c: char): char;
  936.     begin     if (c='G') || (c='g') then showG= c else showG= ' ';
  937.     end();
  938.     function showT( c: char): char;
  939.     begin     
  940.         if (c in ['T','t','U','u']) then showT= c else showT= ' ';
  941.     end();
  942.     function showN( c: char): char;
  943.     begin     
  944.         if (c in ['A','a','C','c','G','g','T','t','U','u'])
  945.                     then showN= ' ' else showN= c;
  946.     end();
  947.     function showEach( c: char): char;
  948.     begin     showEach= c;
  949.     end();
  950.  
  951.  procedure DrawOneColor(function showChar(c:char):char);
  952.     const
  953.         maxbuf    == 500; //are any displays wider than maxbuf*charwidth?
  954.  var
  955.          longint        i, j, ibeg, iend, rowtop, rowbot;
  956.         len            : longint;
  957.         aSeq        : TSequence;
  958.         hSeq        : CharsHandle;
  959.         cbuf        : packed array [0..maxbuf] of char;
  960.  begin
  961.     ibeg= startCell.h - 1;
  962.     iend= stopCell.h;
  963.  
  964.     rowtop= aRect.top;
  965.     FOR j = startCell.v TO stopCell.v){
  966.         rowbot = rowtop + rowHeight - fRowInset;  
  967.         aSeq= TSequence(fAlnList->at(j));
  968.         if (aSeq!=NULL) && (aSeq->fBases!=NULL) then begin
  969.             handle(hSeq)= aSeq->fBases;
  970.             len= min(maxbuf, min( GetHandleSize(handle(hSeq)),iend) - ibeg);
  971.             for i= 0 to len-1 do cbuf[i]= showChar((*hSeq)^[i+ibeg]);
  972.             
  973.             moveto( qdleft+1, rowbot-5); //<< fix fudged v !
  974.             
  975.             DrawText( &cbuf, 0, len);
  976.             end();
  977.         rowtop = rowbot + fRowInset;
  978.         }
  979.     end(); //DrawOneColor
  980.  
  981.  pascal void DrawAllColors(void)
  982.  VAR
  983.          longint        i, j, ibeg, iend, rowtop, rowbot;
  984.         len            : longint;
  985.         aSeq        : TSequence;
  986.         hSeq        : CharsHandle;
  987.  {
  988.     ibeg= startCell.h - 1;
  989.     iend= stopCell.h;
  990.     rowtop= aQDRect.top;
  991.     FOR j = startCell.v TO stopCell.v){
  992.         rowbot = rowtop + rowHeight - fRowInset;  
  993.         aSeq= TSequence(fAlnList->at(j));
  994.         if ((aSeq!=NULL) && (aSeq->fBases!=NULL)) {
  995.             handle(hSeq)= aSeq->fBases;
  996.             len= min( GetHandleSize(handle(hSeq)),iend) - ibeg;
  997.             moveto( qdleft+1, rowbot-5); //<< fix fudged v !
  998.             if ((aSeq->fKind == kAmino))
  999.                 DrawAlnColors(gAAcolors, gSwapBackground, (*hSeq), ibeg, len)
  1000.             else
  1001.                 DrawAlnColors(gNAcolors, gSwapBackground, (*hSeq), ibeg, len);
  1002.             }
  1003.         rowtop = rowbot + fRowInset;
  1004.         }
  1005.     } //DrawAllColors
  1006.         
  1007. {
  1008.     aRect.left = aRect.left + ((fColInset) >> 1);    // fColInset / 2 
  1009.     aRect.top = aRect.top + ((fRowInset) >> 1);     // fRowInset / 2 
  1010.     /***
  1011.     LocalToWindow( aRect.topleft); //+ ?? mapp3 fix for bad aRect ???
  1012.     LocalToWindow( aRect.botright); /*+ sort of -- window coords are not correct
  1013.             as drawing is done rel. to localview(0,0), but we draw parts of
  1014.             all of long sequence now -- BUT we still get crash when view scrolled
  1015.             to the long sequence -- TScroller problem ???*/
  1016.             //+ !! somewhere someone is probably doing short/int overflow by mistake !
  1017.     ***/  
  1018.     
  1019.     VRectToRect( aRect, aQDRect); //??? do we want this -- truncs at maxint 
  1020.     qdleft         = aQDRect.left;
  1021.     colWidth  = GetColWidth(1);
  1022.     rowHeight = GetRowHeight(1); //fails w/ fNumOfRows=0 !
  1023.  
  1024.     //! need to let TE do its hightlighting... don't need TEDeact??
  1025.   if (fEditRow != 0) {
  1026.        if (fEditSeq->Focus()) ; //??
  1027.         fEditSeq->Show(TRUE,FALSE);  
  1028.         //- if fEditSeq.Focus then TEDeactivate(fEditSeq->fHTE); ---
  1029.         if (Focus) ;
  1030.         }
  1031.         
  1032.     SetPortTextStyle(gAlnTextStyle);
  1033.  
  1034.     if TAlnDoc(GetWindow->fDocument).fUseColor then begin
  1035.         /* DrawAllColors is slower than DrawOneColor x 5 
  1036.             -- do DrawOne for nucs ??*/
  1037.         DrawAllColors(); 
  1038.         /*--
  1039.         RGBForeColor( gAcolor); DrawOneColor(showA);
  1040.         RGBForeColor( gCcolor); DrawOneColor(showC);
  1041.         RGBForeColor( gGcolor); DrawOneColor(showG);
  1042.         RGBForeColor( gTcolor); DrawOneColor(showT);
  1043.       RGBForeColor( gNcolor); DrawOneColor(showN);
  1044.         ---*/
  1045.         end
  1046.     else
  1047.         DrawOneColor(showEach);
  1048.     
  1049.     if (fEditRow != 0) begin
  1050.       if fEditSeq.Focus then TEActivate(fEditSeq->fHTE);  
  1051.         if Focus then ;
  1052.         }
  1053. }
  1054.  
  1055.  
  1056.  
  1057. pascal void TAlnView::DrawContents(void) // override 
  1058. {
  1059.     //?? if ((fEditSeq!=NULL)) fEditSeq->show(FALSE,FALSE);  
  1060.     inherited::DrawContents();
  1061.   /*?? if ((fEditSeq!=NULL)) fEditSeq->show(TRUE,FALSE);  */ 
  1062. }
  1063.  
  1064.  
  1065. pascal void TAlnView::CalcMinFrame(VRect VAR minFrame) // override 
  1066. {
  1067.     inherited::CalcMinFrame( minFrame);
  1068.     /*----
  1069.     minFrame.right=  max(minFrame.right, 10 + fNumOfCols * gAlnCharWidth);
  1070.     minFrame.bottom=  max(minFrame.bottom, 10 + fNumOfRows * GetRowHeight(1));
  1071.     -----*/
  1072. }
  1073.  
  1074.  
  1075.  
  1076. pascal void TAlnView::DoMouseCommand(VPoint VAR theMouse, TToolboxEvent event,
  1077.                                                Point hysteresis) // override 
  1078. VAR
  1079.     aRow, aCol    : short;
  1080.     aCell    : GridCell;
  1081.     aAlnSlider        : TAlnSlider;
  1082.     boolean        aDoubleClick;
  1083.     vpt        : VPoint;
  1084.     GridViewPart        gridPart;    
  1085. {
  1086.     aDoubleClick= event->fClickCount > 1;
  1087.     gridPart= IdentifyPoint(theMouse, aCell);
  1088.     aCol= aCell.h;
  1089.     
  1090.     if (aDoubleClick) {
  1091.         inherited::DoMouseCommand(theMouse,event,hysteresis); 
  1092.         }        
  1093.     else if ((event.IsShiftKeyPressed |event.IsCommandKeyPressed 
  1094.                 || event->IsOptionKeyPressed())) { 
  1095.         inherited::DoMouseCommand(theMouse,event,hysteresis);
  1096.         }        
  1097.     else if (gridPart != badChoice) {
  1098.         aCell    = VPointToLastCell(theMouse);
  1099.         //if TRUE then begin
  1100.         if (isCellSelected(aCell)) {
  1101.             New(aAlnSlider);
  1102.             FailNIL(aAlnSlider);
  1103.             aAlnSlider->IAlnSlider(this, aCol);
  1104.             PostCommand( aAlnSlider);
  1105.             }        else {
  1106.             SetEmptySelection(kHighlight);
  1107.             event->fEventRecord.modifiers = bOr(event->fEventRecord.modifiers,shiftKey);
  1108.                  //!? mimic shiftIsDown when no selection ... ?
  1109.             inherited::DoMouseCommand(theMouse,event,hysteresis); 
  1110.             }
  1111.         }
  1112. }
  1113.  
  1114.  
  1115.  
  1116. pascal TAlnView::HandleMouseDown( VPoint theMouse, TToolboxEvent event, 
  1117.                              hysteresis: Point):Boolean; // override 
  1118. VAR
  1119.         aCell    : GridCell;
  1120. {        
  1121.     if (!(fLocked || event.IsShiftKeyPressed || event.IsCommandKeyPressed 
  1122.         || event->IsOptionKeyPressed())) {  
  1123.         SetEmptySelection(kHighlight); 
  1124.         if (fAlnDoc->fAlnIndex!=NULL) fAlnDoc->fAlnIndex->SetEmptySelection(kHighlight); 
  1125.         aCell= VPointToLastCell(TheMouse);
  1126.         InstallEditSeq(aCell.v,0,0,FALSE);
  1127.         }
  1128.     
  1129.   HandleMouseDown= inherited::HandleMouseDown(theMouse,event,hysteresis);
  1130. }
  1131.         
  1132.  
  1133. pascal Boolean TAlnView::ContainsClipType(ResType aType) // override 
  1134. {
  1135.     ContainsClipType = aType == kAlnScrapType;
  1136.     //!? also (aType == 'TEXT') can be pasted as seq... w/ SeqReadScrap...
  1137. }
  1138.  
  1139. pascal void TAlnView::WriteToDeskScrap(void) // override 
  1140. VAR
  1141.         textScrap    : Handle;
  1142.         err                : OSErr;
  1143.         format        : integer;
  1144. {
  1145.     format= kGenBank;
  1146.     /*--- ??? causing bombs here !!!
  1147.     if (fAlnDoc->fFormatPop == NULL) format= kGenBank
  1148.     else format= fAlnDoc->fFormatPop.fCurrentItem; 
  1149.     ---*/
  1150.     fAlnList->ClearSelections();
  1151.     textScrap= fAlnList->doWriteHandle( format);  
  1152.     err = gClipboardMgr->PutDeskScrapData('TEXT', textScrap);
  1153.     textScrap = DisposeIfHandle(textScrap);
  1154.     FailOSErr(err);
  1155. }
  1156.  
  1157.  
  1158.  
  1159.         
  1160.  
  1161.  
  1162.  
  1163. // TAlnSlider --------------------------------------
  1164.  
  1165. pascal void TAlnSlider::IAlnSlider( TAlnView itsAlnView, integer atRC)
  1166. {
  1167.     fAlnView= itsAlnView;    
  1168.     fOldSeqs= NULL;
  1169.     fNewSeqs= NULL;
  1170.     fOldSelection= NULL;
  1171.     fNewSelection= NULL;
  1172.     
  1173.     IRCShifter(itsAlnView->fDocument, itsAlnView, NULL, h, atRC);
  1174.     fCausesChange= TRUE; //!? fix since RCShifter thinks we make no changes
  1175.     
  1176.     fOldSeqs= TSeqList(NewList); FailNIL( fOldSeqs);
  1177.     fNewSeqs= TSeqList(NewList); FailNIL( fNewSeqs);
  1178.     fOldSelection= NewRgn; FailNil( fOldSelection);
  1179.     fNewSelection= NewRgn; FailNIL( fNewSelection);
  1180.     CopyRgn( itsAlnView->fSelections, fOldSelection);
  1181.     CopyRgn( fOldSelection, fNewSelection);
  1182. }
  1183.  
  1184. pascal void TAlnSlider::Free(void) // override 
  1185. {
  1186.     if ((fNewSeqs!=NULL)) {
  1187.         fNewSeqs->DeleteAll(); //forget objects -- doesn't affect objects 
  1188.         fNewSeqs->Free(); //drop list, not objects
  1189.         }
  1190.     if ((fOldSeqs!=NULL)) fOldSeqs->FreeList(); //drop all objects && list
  1191.     if ((fOldSelection!=NULL)) DisposeRgn( fOldSelection);
  1192.     fOldSelection= NULL;
  1193.     if ((fNewSelection!=NULL)) DisposeRgn( fNewSelection);
  1194.     fNewSelection= NULL;
  1195.     
  1196.     inherited::Free();
  1197. }
  1198.  
  1199.  
  1200. pascal TTracker TAlnSlider::TrackMouse(TrackPhase aTrackPhase, VAR anchorPoint, previousPoint,
  1201.                                  VPoint        nextPoint; Boolean mouseDidMove) // override 
  1202. VAR
  1203.     GridCell        aCell;
  1204.     
  1205.     pascal void DoSlide(void)
  1206.     VAR
  1207.         aCell    : GridCell;
  1208.         longint        start, nbases;
  1209.         integer        left, right, dist, aRow;
  1210.         oldSeq, newSeq    : TSequence;
  1211.         vLoc    : VRect;
  1212.     {
  1213.         dist= fNewRC - fOldRC;
  1214.         OffsetRgn( fNewSelection, dist, 0);
  1215.         
  1216.         left= fGrid.FirstSelectedCell.h;
  1217.         right= fGrid.LastSelectedCell.h;
  1218.         FOR aRow= fGrid.FirstSelectedCell.v TO fGrid.LastSelectedCell.v){
  1219.             aCell.h= left;
  1220.             aCell.v= aRow;
  1221.             while (aCell.h<right) && !fGrid->isCellSelected(aCell))aCell.h= aCell.h+1;
  1222.             start= aCell.h - 1;
  1223.             while (aCell.h<right) && fGrid->isCellSelected(aCell))aCell.h= aCell.h+1;
  1224.             nbases= aCell.h - start;
  1225.             if ((nBases>0)) {
  1226.                 oldSeq= fAlnView->fAlnList->SeqAt(aRow);
  1227.                 oldSeq->fIndex= aRow;
  1228.                 oldSeq->SetSelection( start, nbases);
  1229.                 
  1230.                 newSeq= oldSeq->Slide( dist); //< ?? TSeqChangeCmd !?
  1231.                 
  1232.                 oldSeq->ClearSelection();        // 12nov92 - fix for write trunc bug? 
  1233.                 if ((newSeq!=NULL)) {
  1234.                     newSeq->ClearSelection();
  1235.                     fOldSeqs->InsertLast(oldSeq);
  1236.                     fNewSeqs->InsertLast(newSeq);
  1237.                   }
  1238.                 }
  1239.             }
  1240.         }
  1241.         
  1242. {
  1243.     if (aTrackPhase == trackRelease then {
  1244.         aCell    = fGrid->VPointToLastCell(nextPoint);
  1245.         fNewRC= aCell.vh[fRowCol];
  1246.         if fNewRC != fOldRC) DoSlide;
  1247.         }
  1248.     TrackMouse = this;
  1249. }
  1250.  
  1251.  
  1252. pascal void TAlnSlider::DoIt(void) // override 
  1253. /* insert "-" at left/5'/bottom of sequence if dist>0
  1254.     squeeze out "-" at top/3' of sequence.
  1255.     If dist<0 then slide opposite direction.
  1256. */
  1257. VAR    
  1258.     integer        zeroshift, left, i;
  1259.     
  1260.     pascal void UpdateEdWinds( TSequence oldSeq, newSeq)
  1261.         pascal void checkOpenEdWinds( TWindow aWind)
  1262.         {
  1263.             if (Member(TObject(aWind), TSeqedWindow)) 
  1264.                 if (TSeqedWindow(aWind).fSequence == oldSeq) { 
  1265.                     TSeqedWindow(aWind)->ReplaceSeq(newSeq);
  1266.                     aWind->ForceRedraw();
  1267.                     }
  1268.         }
  1269.     {
  1270.         TDocument(fContext)->ForAllWindowsDo(checkOpenEdWinds);
  1271.     }
  1272.  
  1273.     pascal void ReplaceViewSeq( TSequence aSeq)
  1274.     VAR  vLoc    : VRect;
  1275.     {
  1276.         fAlnView->fAlnList->AtPut( aSeq->fIndex, aSeq);
  1277.         fAlnView->RowToVRect( aSeq->fIndex, 1, vLoc);
  1278.         fAlnView->InvalidateVRect( vLoc);
  1279.     }
  1280.     
  1281. {
  1282.     if fNewRC != fOldRC then {
  1283.         fNewSeqs->Each( replaceViewSeq);
  1284.         zeroshift= fAlnView->fAlnList->ZeroOrigin(); //!?
  1285.         if ((zeroshift!=0)) {
  1286.             // THIS is getting messy w/ undo/redo because zeroOrigin affects All seqs!
  1287.             fAlnView->UpdateAllWidths();
  1288.             left= (*fNewSelection)->rgnBBox.left;
  1289.             if (left + zeroshift <= 0) then zeroshift= -left + 1; //??
  1290.             offsetRgn( fNewSelection, zeroshift, 0); 
  1291.             fAlnView->ForceRedraw(); 
  1292.             }
  1293.         fGrid->SetSelection( fNewSelection, !kExtend, kHighlight, kSelect);
  1294.         FOR i= 1 to fNewSeqs->GetSize())UpdateEdWinds( TSequence(fOldSeqs->At(i)), TSequence(fNewSeqs->At(i)));
  1295.         fCommandDone= True;
  1296.         }
  1297. }
  1298.  
  1299.  
  1300. #pragma segment ADoCommand
  1301.  
  1302. pascal void TAlnSlider::UndoIt(void) // override 
  1303. VAR  tmp: TSeqList; RgnHandle tmpRgn,
  1304. {
  1305.     if fNewRC != fOldRC then {
  1306.         tmp= fOldSeqs; 
  1307.         fOldSeqs= fNewSeqs;
  1308.         fNewSeqs= tmp;
  1309.         tmpRgn= fOldSelection;
  1310.         fNewSelection= fOldSelection;
  1311.         fOldSelection= tmpRgn;
  1312.         DoIt();
  1313.         fCommandDone= False; 
  1314.         }
  1315. }
  1316.  
  1317.  
  1318. #pragma segment ADoCommand
  1319.  
  1320. pascal void TAlnSlider::RedoIt(void) // override 
  1321. {
  1322.     UndoIt();
  1323.     fCommandDone= True; 
  1324. }
  1325.  
  1326. pascal void TAlnSlider::Commit(void) // override 
  1327. {
  1328.     this->DoNotification();
  1329. }
  1330.  
  1331. pascal void TAlnSlider::DrawFeedback( VPoint anchorPoint, nextPoint) // override 
  1332. VAR
  1333.     RgnHandle        aSelectRgn;
  1334.     deltah     : longint;
  1335.     abounds    : VRect;
  1336.     aCell        : GridCell;
  1337. {
  1338.     // horizontal slider...
  1339.     aCell    = fGrid->VPointToLastCell(nextPoint);
  1340.     aSelectRgn= NewRgn;
  1341.     fGrid->CellsToPixels( fGrid->fSelections, aSelectRgn);
  1342.     fGrid->CellToVRect( aCell, abounds);
  1343.     deltah= abounds.left - anchorPoint.h;
  1344.     OffsetRgn( aSelectRgn, deltah, 0);
  1345.     FrameRgn( aSelectRgn);
  1346.     DisposeRgn( aSelectRgn);
  1347. }
  1348.  
  1349.  
  1350.         
  1351.         
  1352.         
  1353. // TAlnIndex     ------------------
  1354.  
  1355. pascal void TAlnIndex::GetItemText(integer anItem, str255 var aString) // override 
  1356. VAR  aSeq: TSequence;
  1357. {
  1358.      aString= '';
  1359.   if ((fAlnList!=NULL) && (anItem <= fAlnList->fSize)) {
  1360.         aSeq= TSequence(fAlnList->at(anItem));
  1361.         if aSeq!=NULL then aString= aSeq->fName;
  1362.         }
  1363. }
  1364.  
  1365. pascal void TAlnIndex::UpdateSize(void)
  1366. VAR    diff: integer;
  1367. {
  1368.     if ((fAlnView!=NULL)) {
  1369.         diff= fAlnView->fNumOfRows - fNumOfRows;
  1370.         if ((diff>0)) InsRowLast( 1, fAlnView->fRowheight)     
  1371.         else if ((diff<0)) DelItemLast( -diff);
  1372.         }    else
  1373.         DelItemLast(fNumOfRows);
  1374. }
  1375.  
  1376. pascal void TAlnIndex::ReSelect(RgnHandle indexRegion)
  1377. VAR  aCell: GridCell;
  1378. {
  1379.     /*-----
  1380.     aCell = (*indexRegion)->rgnBBox.topLeft;
  1381.     if (!IsCellVisible(aCell)) PositionAtCell(aCell);                 
  1382.     ----*/
  1383.     
  1384.     if (!EqualRect((*indexRegion)->rgnBBox, (*fSelections)->rgnBBox)) {
  1385.         /*---- ??
  1386.         WITH fAlnDoc){
  1387.             fAlnView->SetEmptySelection(kHighlight);  
  1388.             }
  1389.         -----*/
  1390.         SetSelection(indexRegion, kDontExtend, kHighlight, kSelect);
  1391.         }
  1392. }
  1393.  
  1394.  
  1395.  
  1396. pascal TAlnIndex::HandleMouseDown( VPoint theMouse, TToolboxEvent event, 
  1397.                              hysteresis: Point):Boolean; // override 
  1398. {        
  1399.     fAlnView->DeInstallEditSeq();
  1400.     fAlnView->SetEmptySelection(kHighlight); 
  1401.     
  1402.   HandleMouseDown= inherited::HandleMouseDown(theMouse,event,hysteresis);
  1403. }
  1404.  
  1405. pascal void TAlnIndex::DoMouseCommand(VPoint VAR theMouse, TToolboxEvent event,
  1406.                                                Point hysteresis) // override 
  1407. VAR
  1408.     aRow, aCol    : short;
  1409.     aCell    : GridCell;
  1410.     aAlnShifter        : TAlnShifter;
  1411.     boolean        aDoubleClick;
  1412.     aName    : Str255;
  1413.     vpt        : VPoint;
  1414.     GridViewPart        gridPart;
  1415.     aSeq    : TSequence;
  1416.     
  1417. {
  1418.     aDoubleClick= event->fClickCount > 1;
  1419.     gridPart= IdentifyPoint(theMouse, aCell);
  1420.     aRow= aCell.v;
  1421.     
  1422.     if (aDoubleClick) {
  1423.         aSeq= TSequence(fAlnList->At(aRow));
  1424.         if (aSeq!=NULL)) TAlnDoc(fDocument)->OpenSeqedWindow(aSeq);
  1425.         }        
  1426.     else if ((event.IsShiftKeyPressed |event->IsCommandKeyPressed())) { 
  1427.         inherited::DoMouseCommand(theMouse,event,hysteresis) 
  1428.         }        
  1429.     else if (gridPart != badChoice) {
  1430.         aCell    = VPointToLastCell(theMouse);
  1431.         //if TRUE then begin
  1432.         if (isCellSelected(aCell)) {
  1433.             GetItemText(aRow, aName);
  1434.             New(aAlnShifter);
  1435.             FailNIL(aAlnShifter);
  1436.             aAlnShifter->IAlnShifter(this, fAlnView, aRow, aName);
  1437.             PostCommand( aAlnShifter);
  1438.             }        else
  1439.             inherited::DoMouseCommand(theMouse,event,hysteresis); 
  1440.         }
  1441. }
  1442.  
  1443.  
  1444.  
  1445.  
  1446.  
  1447. // TAlnShifter --------------------------------
  1448.  
  1449.  
  1450. pascal void TAlnShifter::IAlnShifter(
  1451.         TGridView        itsView; TAlnView itsAlnView, atRC: integer; seqName aName)
  1452. {
  1453.     fAlnView= itsAlnView;
  1454.     fName        = aName;
  1455.     IRCShifter(itsView->fDocument, itsView, itsAlnView, v, atRC);
  1456.     fCausesChange= TRUE; //!? fix since RCShifter thinks we make no changes
  1457.  
  1458.     fAlnView->SetEmptySelection(kHighlight); //? or move select rgn rows ?
  1459. }
  1460.  
  1461. pascal void TAlnShifter::DoShift( integer fromRC, toRC) // override 
  1462.     /*!? This won't do, 
  1463.             need to move fAlnList.contents ?? or revise TAlnIndex.GetItemText
  1464.     --  don't Swap from/to,
  1465.           need to remove seq at from, then insert seq at to.
  1466.             Need to shift a multiple selection...
  1467.     --*/
  1468. VAR
  1469.     vRect        vFrom, vTo;
  1470.     TSequence        fromSeq, toSeq;
  1471.     integer        aFromRow, aToRow, indx, saveEdit; 
  1472.     integer        saveStart, saveEnd;
  1473.     GridCell        aCell;
  1474.     
  1475.     pascal void relocate( TSequence aSeq)
  1476.     vRect        VAR vLoc; vPoint vSize,
  1477.     {
  1478.         indx= indx+1;
  1479.         if (indx >= aFromRow) && (indx <= aToRow) then {
  1480.             //! also need to shift any selection or deselect all...
  1481.           fAlnView->RowToVRect( indx, 1, vLoc);
  1482.             fAlnView->InvalidateVRect( vLoc);
  1483.             if indx == saveEdit then {
  1484.                 fAlnView->fEditRow= saveEdit;
  1485.                 fAlnView->fEditSeq->Locate( vLoc.topleft, TRUE);
  1486.                 vSize= fAlnView->fEditSeq.fSize;
  1487.                 fAlnView->fEditSeq->Resize( vSize, FALSE);  
  1488.                 }
  1489.             aCell.v= indx;
  1490.             fGrid->InvalidateCell(aCell);
  1491.             }
  1492.     }
  1493.     
  1494. {
  1495.     //- for firstSelected to lastSelected do... 
  1496.  
  1497.     fromSeq    = TSequence(fAlnView->fAlnList->At(fromRC));
  1498.     toSeq        = TSequence(fAlnView->fAlnList->At(toRC));
  1499.     if (fromSeq!=NULL) && (toSeq!=NULL) then {
  1500.         fAlnView->fAlnList->Delete(fromSeq);
  1501.         fAlnView->fAlnList->InsertBefore(toRC, fromSeq);
  1502.         if fromRC > toRC then begin 
  1503.             aFromRow= toRC; aToRow= fromRC; 
  1504.             }        else begin
  1505.             aFromRow= fromRC; aToRow= toRC; 
  1506.             }
  1507.         saveEdit= fAlnView->fEditRow;
  1508.         if saveEdit == fromRC then saveEdit= toRC
  1509.         else if fromRC > toRC then saveEdit= saveEdit + 1 
  1510.         else if fromRC < toRC then saveEdit= saveEdit - 1; 
  1511.         indx= 0;
  1512.         aCell.h= 1;
  1513.         fAlnView->fAlnList->Each(relocate);    
  1514.         fGrid->SetEmptySelection(kHighlight); //?
  1515.         }
  1516. }
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.  
  1523.  
  1524. // TAlnHIndex    -----------------
  1525.  
  1526. pascal TAlnHIndex::HandleMouseDown( VPoint theMouse, TToolboxEvent event, 
  1527.                              hysteresis: Point):Boolean; // override 
  1528. {        
  1529.     fAlnView->DeInstallEditSeq();
  1530.     //- fAlnView->SetEmptySelection(kHighlight); 
  1531.   HandleMouseDown= inherited::HandleMouseDown(theMouse,event,hysteresis);
  1532. }
  1533.  
  1534. pascal void TAlnHIndex::GetText(aCell:GridCell; Str255 VAR aString) // override 
  1535. //! don't need w/ .Draw method...
  1536. {
  1537.      aString= '';
  1538.     if aCell.h mod 10 == 0 then NumToString(aCell.h, aString);
  1539. }
  1540.  
  1541. pascal void TAlnHIndex::UpdateWidth(void)
  1542. {
  1543.     if fAlnView->fNumOfCols > fNumOfCols then 
  1544.         InsColLast( fAlnView->fNumOfCols-fNumOfCols, gAlnCharWidth)
  1545.     else if fAlnView->fNumOfCols < fNumOfCols then
  1546.         DelColLast( fNumOfCols-fAlnView->fNumOfCols);
  1547.     SetColWidth(1, fNumOfCols, gAlnCharWidth);  
  1548. }
  1549.  
  1550.  
  1551. pascal void TAlnHIndex::DrawCell(GridCell aCell, VRect aRect) // override 
  1552. //! left side of nums are badly clipped on scroll left
  1553. var  nums: str255;
  1554.          ws    : integer;
  1555.          Rect        aQDRect;
  1556. {
  1557.     VRectToRect( aRect, aQDRect);
  1558.     if ((aCell.h % 10 == 0)) {
  1559.         MoveTo(aQDRect.left, aQDRect.bottom);
  1560.         Line(0,-3);
  1561.         NumToString( aCell.h, nums);
  1562.         ws= StringWidth(nums);
  1563.         Move(-ws div 2, -1);
  1564.         DrawString(nums);
  1565.         }    else if ((aCell.h % 5 == 0)) {
  1566.         MoveTo(aQDRect.left, aQDRect.bottom);
  1567.         Line(0,-6);
  1568.         }
  1569. }
  1570.  
  1571. pascal void TAlnHIndex::Draw(VRect area) // override 
  1572. {
  1573.     inherited::Draw(area); 
  1574. }
  1575.  
  1576.  
  1577. /***********
  1578. pascal void TAlnHIndex::Draw(VRect area) // override 
  1579. var
  1580.     rect        ter ;
  1581.     integer        cat, ecat, v, ws ;
  1582.     nums    : Str255;
  1583.     pt        : point;
  1584. {
  1585.     v        = area.bottom;
  1586.     
  1587.     cat= 1;
  1588.     pt= TEGetPoint(cat, fSeq->fHTE);
  1589.     if pt.h < area.left then begin
  1590.                                                                   //! this is off by 30-40+ for 2000+ nucs
  1591.         ws= gAlnCharWidth;  
  1592.       cat= cat + (area.left - pt.h) / ws;
  1593.         pt= TEGetPoint(cat, fSeq->fHTE);
  1594.         if pt.h > area.left then
  1595.             cat= cat - (pt.h - area.left) / ws;
  1596.         end();
  1597.         
  1598.     ecat= fSeq.(*fHTE)->teLength;
  1599.  
  1600.     repeat
  1601.         pt= TEGetPoint(cat, fSeq->fHTE);
  1602.         if pt.h >= area.left then begin
  1603.             moveto(pt.h, v);
  1604.             if (cat mod 10 == 0) then begin
  1605.                 line(0,-3);
  1606.                 NumToString( cat, nums);
  1607.                 ws= StringWidth(nums);
  1608.                 move(-ws div 2,-1);
  1609.                 drawstring(nums);
  1610.                 end
  1611.             else if (cat mod 5 == 0) then
  1612.                 line(0,-8);
  1613.             end();
  1614.         cat= cat + 1;
  1615.   until (pt.h >= area.right) || (cat >= ecat);
  1616.     
  1617.     //- inherited::Draw(area); 
  1618. }
  1619. ********/        
  1620.     
  1621.         
  1622.         
  1623.         
  1624.         
  1625.         
  1626.         
  1627. // TAlnScroller ------------------------
  1628.  
  1629. pascal void TAlnScroller::Free(void) // override 
  1630. {
  1631.     fRowScroller->fMainScroller= NULL;
  1632.     fColumnScroller->fMainScroller= NULL;
  1633.     fRowScroller= NULL;
  1634.     fColumnScroller= NULL;
  1635.     inherited::Free();
  1636. }
  1637.  
  1638. pascal void TAlnScroller::SingleScroll(VPoint delta, Boolean redraw)
  1639. {
  1640.     inherited::DoScroll(delta, redraw); // scroll the main view 
  1641.     //+? fix TAlnView origin to scroller origin ???
  1642.     //+ GetAlnView->fTranslation= fTranslation;
  1643. }
  1644.  
  1645. pascal void TAlnScroller::DoScroll(VPoint delta, Boolean redraw) // override 
  1646. {
  1647.     if ((delta.v != 0) && (fRowScroller!=NULL)) fRowScroller->SingleScroll(delta, redraw);
  1648.     if ((delta.h != 0) && (fColumnScroller!=NULL)) fColumnScroller->SingleScroll(delta, redraw);
  1649.     inherited::DoScroll(delta, redraw); // scroll the main view 
  1650.     //+? fix TAlnView origin to scroller origin ???
  1651.     //+ GetAlnView->fTranslation= fTranslation;
  1652. }
  1653.  
  1654.  
  1655.  
  1656. pascal void TSideScroller::Free(void) // override 
  1657. {
  1658.     fMainScroller->fRowScroller= NULL;
  1659.     fMainScroller->fColumnScroller= NULL;
  1660.     fMainScroller= NULL;
  1661.     inherited::Free();
  1662. }
  1663.  
  1664. pascal void TSideScroller::SingleScroll(VPoint delta, Boolean redraw)
  1665. {
  1666.     inherited::DoScroll(delta, redraw); // scroll the main view 
  1667. }
  1668.  
  1669. pascal void TSideScroller::DoScroll(VPoint delta, Boolean redraw) // override 
  1670. {
  1671.     if ((delta.h != 0) && (fMainScroller!=NULL)) fMainScroller->SingleScroll(delta, redraw);
  1672.     if ((delta.v != 0) && (fMainScroller!=NULL)) fMainScroller->SingleScroll(delta, redraw);
  1673.     inherited::DoScroll(delta, redraw); // scroll the main view 
  1674. }
  1675.  
  1676.  
  1677.  
  1678. /* TAlnDlog ------------------------*/        
  1679.  
  1680. pascal void TAlnDlog::DoMouseCommand(VPoint VAR theMouse, TToolboxEvent event,
  1681.                                                Point hysteresis) // override 
  1682. {
  1683.     if (TAlnDoc(fDocument).fAlnView != NULL)
  1684.         TAlnDoc(fDocument).fAlnView->SetEmptySelection(kHighlight);
  1685.     inherited::DoMouseCommand( theMouse, event, hysteresis);
  1686. }
  1687.  
  1688. pascal void TAlnDlog::CalcMinFrame(VRect VAR minFrame) // override 
  1689. //! need to check CalcMinFrame of window 
  1690. var  aDoc: TAlnDoc;
  1691.          longint        dsize;
  1692.          VRect        listVRect;
  1693.          TScroller        aScroll;
  1694.          Vpoint        scrollSize ;
  1695. {
  1696.   inherited::CalcMinFrame(minFrame); //do horiz ?
  1697. /**********
  1698.     aScroll= NULL;
  1699.     aDoc= TAlnDoc(fDocument);
  1700.     dsize= 0;
  1701.     if ((aDoc->fSeqList != NULL)) 
  1702.         dsize= aDoc->fSeqList.fSize + 2;
  1703.     /*-- 
  1704.         fSeqListView is NULL now when called from NewTemplateWindow 
  1705.         at top of TSeqListDoc.DoMakeViews
  1706.     ---*/
  1707.     if ((aDoc->fAlnView != NULL)) {
  1708.         aDoc->fAlnView->GetFrame( listVRect);
  1709.         dsize= listVRect.top + (aDoc->fAlnView.fRowHeight * dsize);
  1710.         aScroll = TAlnScroller(aDoc->fAlnView->GetScroller(TRUE));
  1711.         scrollSize.h= 10 + aDoc->fAlnView.fNumOfCols * gAlnCharWidth;
  1712.         scrollSize.v= 10 + aDoc->fAlnView.fNumOfRows * aDoc->fAlnView->GetRowHeight(1);
  1713.         }    else {
  1714.         scrollSize.v= minFrame.bottom;
  1715.         scrollSize.h= minFrame.right;
  1716.         }
  1717.     minFrame.bottom= max(minFrame.bottom, dsize);
  1718.  
  1719. /*?! didn't need til we made view a prefwindow!!!!:    
  1720.     if ((aScroll!=NULL)) aScroll->SetScrollLimits(scrollSize, kDontRedraw); 
  1721. */
  1722. ******/
  1723. }
  1724.  
  1725.  
  1726.  
  1727.  
  1728.  
  1729. // TAlnWindow --------------------------
  1730.  
  1731. pascal void TAlnWindow::IAlnWindow(void)
  1732. {
  1733.     IPrefWindow();
  1734.     fWantSave= TRUE;
  1735. }
  1736.  
  1737. pascal void TAlnWindow::SetPrefID(void) /* override */ 
  1738. {
  1739.     gPrefWindID= kAlnDocID; gPrefWindName= 'TAlnWindow';
  1740. }
  1741.  
  1742.  
  1743.  
  1744.  
  1745.  
  1746.  
  1747.  
  1748. /* TSeqChangeCmd ------------------------*/        
  1749.  
  1750. pascal TSequence TSeqChangeCmd::ChangeToNew( oldSeq:TSequence);
  1751. //! Override this for each type of sequence changer 
  1752. {     ChangeToNew= TSequence(oldSeq->Clone());
  1753. }
  1754.  
  1755. pascal TSequence TSeqReverseCmd::ChangeToNew( oldSeq:TSequence); // override 
  1756. {      ChangeToNew= oldSeq->Reverse();
  1757. }
  1758. pascal TSequence TSeqComplementCmd::ChangeToNew( oldSeq:TSequence); // override 
  1759. {      ChangeToNew= oldSeq->Complement();
  1760. }
  1761. pascal TSequence TSeqRevComplCmd::ChangeToNew( oldSeq:TSequence); // override 
  1762. VAR  tempSeq: TSequence;
  1763. {      
  1764.         tempSeq= oldSeq->Reverse();  
  1765.         ChangeToNew= tempSeq->Complement();
  1766.         tempSeq->Free();  
  1767. }
  1768.  
  1769. pascal TSequence TSeqCompressCmd::ChangeToNew( oldSeq:TSequence); // override 
  1770. {      ChangeToNew= oldSeq->Compress();
  1771. }
  1772. pascal TSequence TSeqDna2RnaCmd::ChangeToNew( oldSeq:TSequence); // override 
  1773. {      ChangeToNew= oldSeq->Dna2Rna( TRUE);
  1774. }
  1775. pascal TSequence TSeqRna2DnaCmd::ChangeToNew( oldSeq:TSequence); // override 
  1776. {      ChangeToNew= oldSeq->Dna2Rna( FALSE);
  1777. }
  1778. pascal TSequence TSeqTranslateCmd::ChangeToNew( oldSeq:TSequence); // override 
  1779. {      ChangeToNew= oldSeq->Translate();
  1780. }
  1781. pascal TSequence TSeqLockIndelsCmd::ChangeToNew( oldSeq:TSequence); // override 
  1782. {      ChangeToNew= oldSeq->LockIndels(True);
  1783. }
  1784. pascal TSequence TSeqUnlockIndelsCmd::ChangeToNew( oldSeq:TSequence); // override 
  1785. {      ChangeToNew= oldSeq->LockIndels(False);
  1786. }
  1787.  
  1788.         
  1789. pascal void TSeqChangeCmd::ISeqChangeCmd( TAlnDoc itsAlnDoc , 
  1790.                                         TView        itsView ; TSeqList itsSeqs )
  1791. VAR start, nbases: longint;
  1792.     TCommandHandler        theContext; 
  1793.  
  1794.         pascal void CopyToNew( TSequence oldSeq)
  1795.         {
  1796.             fNewSeqs->InsertLast(this->ChangeToNew(oldSeq));
  1797.         }
  1798.  
  1799. {
  1800.     //- gApplication->CommitLastCommand(); -- Paste seqs is giving probs...
  1801.  
  1802.     fAlnView= itsAlnDoc->fAlnView;
  1803.     fAlnView->DeinstallEditSeq(); //! prevent mangle do to fBases newhandle 
  1804.     //- if (fAlnView->Focus()) ; --- what do/did we need this for ??
  1805.     fOldSeqs= NULL;
  1806.     fNewSeqs= NULL;
  1807.     // theContext:    TCommandHandler;
  1808.     theContext= itsView->GetContext(cSeqChange);
  1809.     ICommand(cSeqChange, theContext, kCanUndo, kCausesChange, theContext);
  1810.  
  1811.     if ((itsSeqs == NULL)) itsAlnDoc->GetSelection( TRUE, TRUE, itsSeqs, start, nbases);
  1812.     FailNIL( itsSeqs);
  1813.     fOldSeqs= itsSeqs;
  1814.  
  1815.     fNewSeqs= TSeqList(NewList); 
  1816.     FailNIL(fNewSeqs);
  1817.     fOldSeqs->Each( CopyToNew);
  1818. }    
  1819.  
  1820.  
  1821. pascal void TSeqChangeCmd::Free(void) // override 
  1822. {
  1823.     if ((fNewSeqs!=NULL)) {
  1824.         fNewSeqs->DeleteAll(); //forget objects -- doesn't affect objects 
  1825.         fNewSeqs->Free();             //drop list, not objects
  1826.         }
  1827.     if ((fOldSeqs!=NULL)) fOldSeqs->FreeList();     //drop all objects && list
  1828.     inherited::Free();
  1829. }
  1830.  
  1831. pascal void TSeqChangeCmd::UndoIt(void) // override 
  1832. VAR    tempList: TSeqList;
  1833. {
  1834.     tempList= fNewSeqs;
  1835.     fNewSeqs= fOldSeqs;
  1836.     fOldSeqs= tempList;
  1837.     Doit();
  1838.     fCommandDone= False; 
  1839. }
  1840.  
  1841. pascal void TSeqChangeCmd::RedoIt(void) // override 
  1842. {
  1843.     UndoIt();
  1844.     fCommandDone= True; 
  1845. }
  1846.  
  1847. pascal void TSeqChangeCmd::DoIt(void) // override 
  1848. VAR
  1849.     aFromRow, aToRow, indx, saveEdit,
  1850.     integer        i, j, nseqs, saveStart, saveEnd;
  1851.     GridCell        aCell;
  1852.     TSequence        oldSeq, newSeq;
  1853.     
  1854.     pascal void UpdateEdWinds( TSequence oldSeq, newSeq)
  1855.         pascal void checkOpenEdWinds( TWindow aWind)
  1856.         {
  1857.             if (Member(TObject(aWind), TSeqedWindow)) 
  1858.                 if (TSeqedWindow(aWind).fSequence == oldSeq) { 
  1859.                     TSeqedWindow(aWind)->ReplaceSeq(newSeq);
  1860.                     aWind->ForceRedraw();
  1861.                     }
  1862.         }
  1863.     {
  1864.         TDocument(fContext)->ForAllWindowsDo(checkOpenEdWinds);
  1865.     }
  1866.  
  1867.     pascal void relocate( TSequence aSeq)
  1868.     var     
  1869.             vRect        vLoc; vPoint vSize,
  1870.     {
  1871.         indx= indx+1;
  1872.         if (indx >= aFromRow) && (indx <= aToRow) then {
  1873.             //! also need to shift any selection or deselect all...
  1874.           fAlnView->RowToVRect( indx, 1, vLoc);
  1875.             fAlnView->InvalidateVRect( vLoc);
  1876.             if indx == saveEdit then {
  1877.                 fAlnView->fEditRow= saveEdit;
  1878.                 fAlnView->fEditSeq->Locate( vLoc.topLeft, TRUE);
  1879.                 vSize= fAlnView->fEditSeq.fSize;
  1880.                 fAlnView->fEditSeq->Resize( vSize, FALSE);  
  1881.                 }
  1882.             aCell.v= indx;
  1883.             fAlnView->InvalidateCell(aCell);
  1884.             }
  1885.     }
  1886.     
  1887. {
  1888.     if (fOldSeqs!=NULL) && (fNewSeqs!=NULL) then begin
  1889.         saveEdit= fAlnView->fEditRow;        
  1890.         aFromRow= 0;
  1891.         aToRow= 0;
  1892.         nseqs= fNewSeqs->GetSize();
  1893.         for i= 1 to nseqs do {
  1894.             newSeq= TSequence( fNewSeqs->At(i));
  1895.             oldSeq= TSequence( fOldSeqs->At(i));
  1896.             j= fAlnView->fAlnList->GetEqualItemNo( oldSeq);
  1897.             if (j>0) then {
  1898.                 fAlnView->fAlnList->InsertBefore( j, newSeq);
  1899.                 fAlnView->fAlnList->Delete( oldSeq);
  1900.                 if (aFromRow == 0) then aFromRow= j
  1901.                 else aToRow= j;
  1902.                 }    
  1903.             UpdateEdWinds( oldSeq, newSeq);
  1904.             }
  1905.         
  1906.         if ((aToRow=0)) aToRow= aFromRow;
  1907.         indx= 0;
  1908.         aCell.h= 1;
  1909.         fAlnView->fAlnList->Each(relocate);    
  1910.         //- fAlnView->SetEmptySelection(kHighlight);*/ /*?
  1911.         fCommandDone= True; 
  1912.         }
  1913. }
  1914.  
  1915. pascal void TSeqChangeCmd::Commit(void) // override 
  1916. {
  1917.     this->DoNotification();
  1918. }
  1919.  
  1920.  
  1921.  
  1922.  
  1923.  
  1924.  
  1925. /* TAlnDoc ------------------------*/        
  1926.         
  1927. CONST
  1928.     mColorButHit == 1001;
  1929.     mMonoButHit    == 1002;
  1930.     mLockButHit == kLockIconID;    
  1931.  
  1932. #pragma segment AClose
  1933.  
  1934. pascal void TAlnDoc::Close(void) /* override */ 
  1935. {
  1936.  
  1937.     /*! if !gConfiguration.hasColorQD then app bombs when this doc is closed 
  1938.             -- DUE TO RemoveSubview(fColorButton) !!!!!! */
  1939.             
  1940.         /* patches for prefwindow */        
  1941.     if ((fUseColor) && (fColorButton!=NULL)) fColorButton->fHilite= TRUE;
  1942.     //- if (fAlnWindow!=NULL) fAlnWindow->SetTitle('<<!=>> Align');  
  1943.   inherited::Close();
  1944. }
  1945.  
  1946.  
  1947. #pragma segment ARes
  1948.         
  1949. pascal void TAlnDoc::IAlnDoc( TFile itsFile)
  1950. {    
  1951.     fAlnView= NULL;
  1952.     fAlnIndex= NULL;
  1953.     fAlnHIndex= NULL;
  1954.     fUseColor= FALSE;
  1955.     fColorButton= NULL;
  1956.     fMonoButton= NULL;
  1957.     fAlnWindow= NULL;
  1958.     fSaveSelection= False;
  1959.     
  1960.     ISeqListDoc(itsFile);
  1961. }
  1962.  
  1963.  
  1964.  
  1965. pascal void TAlnDoc::DoMakeViews(Boolean forPrinting) // override 
  1966. VAR
  1967.         s            : str255;
  1968.         aView    : TAlnWindow;
  1969.         TAlnDlog        aDialogView;
  1970.         TStdPrintHandler        aHandler;
  1971.         TAlnScroller        aAlnScroller;
  1972.         TSideScroller        aSideScroller;
  1973.         vsize        : VPoint;
  1974.         hIcon        : Handle;
  1975. {
  1976. /*------- TSeqListDoc.MakeViews  -----------*/    
  1977.     fHeadline= NULL;
  1978.     fSeqListView= NULL;
  1979.     fFormatPop= NULL;
  1980.     
  1981.     fAlnWindow = TAlnWindow( gViewServer->NewTemplateWindow(kAlnDocID, this));
  1982.     FailNIL(fAlnWindow);                  
  1983.     fAlnWindow->IAlnWindow();
  1984.     aView= fAlnWindow;
  1985.     
  1986.   fFormatPop= TPopup(aView->FindSubView('pFMT'));
  1987.     if ((fFormatPop!=NULL) && (fInFormat > kUnknown)) 
  1988.         fFormatPop->SetCurrentItem(fInFormat, kDontRedraw);
  1989.     
  1990.     //get superview of window, minus scrolls, for printing
  1991.     aDialogView = TAlnDlog(aView->FindSubView('DLOG')); 
  1992.     
  1993. //!! Substitute TAlnPrintView for this handler.... !!!
  1994.     New(aHandler);
  1995.     FailNIL(aHandler);
  1996.     aHandler->IStdPrintHandler(this,                     // its document 
  1997.                               aDialogView,                    // its view 
  1998.                               !kSquareDots,            // does not have square dots 
  1999.                               kFixedSize,                 // horzontal page size is fixed 
  2000.                               !kFixedSize);            /* vertical page size is variable (could be
  2001.                                                           set to TRUE on non-style TE systems) */
  2002.  
  2003. /*------- TAlnWindow inits -----------*/    
  2004.     
  2005.     fAlnView     = TAlnView(aView->FindSubView(kAlnViewType));
  2006.     FailNIL( fAlnView);
  2007.     fAlnView->IAlnView( this, fSeqList);  
  2008.  
  2009.   fAlnIndex = TAlnIndex(aView->FindSubView('VIND'));
  2010.     FailNIL(fAlnIndex);
  2011.     fAlnIndex->fAlnList= fAlnView->fAlnList;
  2012.     fAlnIndex->fAlnView= fAlnView;
  2013.     
  2014.   fAlnHIndex = TAlnHIndex(aView->FindSubView('HIND'));
  2015.     FailNIL(fAlnHIndex);
  2016.     fAlnHIndex->fAlnView= fAlnView;
  2017.     
  2018.     //! need to have num of seqs here...
  2019.     //- fAlnIndex->DelRowLast(fAlnIndex->fNumOfRows);
  2020.     //- fAlnIndex->InsRowLast(fAlnView->fNumOfRows,fAlnView->GetRowHeight(1));
  2021.  
  2022.     // set up the aln view scroller to scroll the rows and columns too 
  2023.     aAlnScroller = TAlnScroller(fAlnView->GetScroller(TRUE));
  2024.     aSideScroller= TSideScroller(fAlnHIndex->GetScroller(TRUE));
  2025.     aAlnScroller->fColumnScroller= aSideScroller;
  2026.     aSideScroller->fMainScroller= aAlnScroller;
  2027.  
  2028.     //fix for pref saved view w/o active scrolls
  2029.     /*----
  2030.     if ((aAlnScroller!=NULL)) aAlnScroller->fScrollLimit.v= 256;  
  2031.     if ((aAlnScroller!=NULL)) aAlnScroller->fScrollLimit.h= 256;  
  2032.     ----*/
  2033.     
  2034. /*+ ?? will this help/hurt alnview overflow bug ??*/ 
  2035. /*+
  2036.     vsize.h= MaxInt; vsize.v= MaxInt;
  2037.     if ((aAlnScroller!=NULL)) aAlnScroller->SetScrollLimits(vsize, kDontRedraw);
  2038. +*/
  2039.  
  2040.     aSideScroller= TSideScroller(fAlnIndex->GetScroller(TRUE));
  2041.     aAlnScroller->fRowScroller = aSideScroller;
  2042.     aSideScroller->fMainScroller= aAlnScroller;
  2043.     
  2044.     fLockButton= TIcon(aView->FindSubView('LOCK'));
  2045.     fLockButton->fEventNumber= mLockButHit;
  2046.     
  2047.         //fix for prefwindow
  2048.     fAlnView->fLocked= TRUE; // (fLockButton->fRsrcID == kLockIconID);  
  2049.     if (gConfiguration.hasColorQD) 
  2050.         hIcon= Handle(GetCIcon( kLockIconID))
  2051.     else 
  2052.         hIcon= Handle(GetIcon( kLockIconID));
  2053.     fLockButton->SetIcon( hIcon, kDontRedraw);
  2054.  
  2055.     fColorButton= TIcon(aView->FindSubView('iCLR'));
  2056.     fColorButton->fEventNumber= mColorButHit;
  2057.     fMonoButton= TIcon(aView->FindSubView('iMNO'));
  2058.     fMonoButton->fEventNumber= mMonoButHit;
  2059.     fUseColor    = fColorButton->fHilite; //? user pref?
  2060.     fColorButton->fHilite= FALSE;
  2061.     fMonoButton->fHilite= FALSE;
  2062.     if (!gConfiguration.hasColorQD) {
  2063.             /*===    !!! this .RevmoveSubView is causing BOMBS on Close of view 
  2064.             aView->RemoveSubView(fColorButton);
  2065.             aView->RemoveSubView(fMonoButton);
  2066.             ===*/
  2067.         fColorButton->ViewEnable(FALSE, kDontRedraw);
  2068.         fColorButton->Show(FALSE, kDontRedraw);
  2069.         fMonoButton->ViewEnable(FALSE, kDontRedraw);
  2070.         fMonoButton->Show(FALSE, kDontRedraw);
  2071.         fUseColor    = FALSE;
  2072.         }
  2073.  
  2074.     ShowReverted();
  2075. }
  2076.  
  2077.  
  2078.  
  2079.  
  2080. pascal void TAlnDoc::ShowReverted(void) // override 
  2081. VAR  nc : integer;
  2082.          integer        nold, nnew;
  2083. {
  2084.     inherited::ShowReverted(); // ->> TSeqListDoc.ShowReverted !
  2085.     
  2086.     SetPortTextStyle(gAlnTextStyle);  
  2087.     gAlnCharWidth= CharWidth('G');  // must do before widths; get it here when we have a window...
  2088.     gMaxViewCellsBugFix= kMaxCoord / (gAlnCharWidth+4);
  2089.     gMaxViewCellsBugSeen= false;
  2090.     
  2091.     fAlnView->fAlnList= fSeqList;  
  2092.     nold= fAlnView->fNumOfRows;
  2093.     nnew= fSeqList->GetSize();
  2094.     fAlnView->DelRowLast( nold);
  2095.     fAlnView->InsRowLast( nnew, fAlnView->fRowHeight);
  2096.     fAlnView->UpdateAllWidths();
  2097.     
  2098.     fAlnIndex->DelRowLast(fAlnIndex->fNumOfRows);
  2099.     fAlnIndex->InsRowLast(fAlnView->fNumOfRows,fAlnView->GetRowHeight(1));
  2100.     
  2101.     /*--
  2102.     fAlnHIndex->DelColLast( fAlnHIndex->fNumOfRows);
  2103.     fAlnHIndex->InsColLast( fAlnView->fNumOfCols, gAlnCharWidth);
  2104.                 ^^^ done thru UpdateAllWidths...
  2105.     ---*/
  2106.         
  2107.     if (gMaxViewCellsBugSeen) then begin
  2108.         ParamText('a known bug prevents display of more than ~2700 bases',
  2109.                 ' All bases are there, and will be displayed in the edit window.',
  2110.                 'DisplayAlign','');    
  2111.         gApplication->ShowError( -1, msgMyError); 
  2112.         end();
  2113.         
  2114. }
  2115.  
  2116.  
  2117.  
  2118.  
  2119.  
  2120.  
  2121. pascal void PascalClose( text VAR aFile)
  2122. {
  2123.     close( aFile);
  2124. }
  2125.  
  2126.  
  2127. pascal void TAlnDoc::FirstSelection( TSequence VAR aSeq, longint VAR start, nbases)
  2128. VAR        
  2129.         atRow, right    : integer;
  2130.         GridCell        c1, c2, aCell ;
  2131. {
  2132.     c1= fAlnView->FirstSelectedCell();
  2133.     c2= fAlnView->LastSelectedCell();
  2134.     if (!EqualPt( c1, c2)) {
  2135.         right= c2.h;
  2136.         atRow= c1.v;
  2137.         aCell.h= c1.h;
  2138.         aCell.v= atRow;
  2139.         while (aCell.h<right) && !fAlnView->isCellSelected(aCell))aCell.h= aCell.h+1;
  2140.         start= aCell.h - 1;
  2141.         while (aCell.h<right) && fAlnView->isCellSelected(aCell))aCell.h= aCell.h+1;
  2142.         nbases= aCell.h - start;
  2143.         }    else {
  2144.         atRow= fAlnIndex->FirstSelectedItem();
  2145.         start= 0; 
  2146.         nbases= 0; //key for all of seq
  2147.         }
  2148.     if ((atRow < 1)) atRow= 1; //fix No selection to 1st 
  2149.     aSeq= fAlnView->SeqAt( atRow);
  2150.     if ((aSeq!=NULL)) {
  2151.         aSeq->fIndex= atRow;
  2152.         aSeq->SetSelection( start, nbases);
  2153.         }
  2154. }
  2155.  
  2156.  
  2157. pascal void TAlnDoc::GetSelection( boolean equalCount, allAtNoSelection,
  2158.                                             TSeqList        VAR aSeqList; longint VAR start, nbases)
  2159. VAR
  2160.     integer        left, right, top, bottom;
  2161.     aCell    : GridCell;
  2162.     aRow    : longint;
  2163.     aSeq    : TSequence;
  2164.     longint        start1, nbases1;
  2165.     Boolean        wantAll;
  2166.     
  2167.     pascal void AddSeqAtToList( integer aRow)
  2168.     {
  2169.         aSeq= fAlnView->SeqAt( aRow); 
  2170.         if ((aSeq!=NULL)) {
  2171.             /*--- ?? default is use all when nbases==0 !?
  2172.             if (wantAll) {
  2173.                 start1= 0;
  2174.                 nbases1= GethandleSize(aSeq->fBases);
  2175.                 }
  2176.             ---*/
  2177.             aSeq->fIndex= aRow;
  2178.             aSeq->SetSelection( start1, nbases1);
  2179.             aSeqList->InsertLast( aSeq);
  2180.             start= max(start,start1);
  2181.             if ((nBases=0)) nBases= nbases1
  2182.             else nBases= min(nBases,nbases1);
  2183.             }
  2184.     }
  2185.     
  2186. {
  2187.     aSeqList= TSeqList(NewList);
  2188.     FailNIL( aSeqList);
  2189.     
  2190.     left = fAlnView.FirstSelectedCell.h;
  2191.     right= fAlnView.LastSelectedCell.h;
  2192.     top  = fAlnView.FirstSelectedCell.v;
  2193.     bottom= fAlnView.LastSelectedCell.v;
  2194.     start= 0; start1= 0;
  2195.     nBases= 0; nBases1= 0;
  2196.     if ((left!=right) || (top!=bottom)) {
  2197.         wantAll= FALSE;
  2198.         FOR aRow= top TO bottom){
  2199.             if (equalcount) aCell.h= left else aCell.h= 1; 
  2200.             aCell.v= aRow;
  2201.             while (aCell.h<right) && !fAlnView->isCellSelected(aCell))aCell.h= aCell.h+1;
  2202.             start1= aCell.h - 1;
  2203.             if (equalCount)
  2204.                 while (aCell.h<right) && fAlnView->isCellSelected(aCell))aCell.h= aCell.h+1
  2205.             else 
  2206.                 while fAlnView->isCellSelected(aCell))aCell.h= aCell.h+1;
  2207.             nbases1= aCell.h - start1;
  2208.             AddSeqAtToList( aRow);
  2209.             }
  2210.         start = left - 1;
  2211.         nbases= right - start;  
  2212.         }    else if ((fAlnIndex.LastSelectedItem=0)) {
  2213.         wantAll= TRUE;
  2214.         if (allAtNoSelection) fAlnIndex->AllItemsDo( AddSeqAtToList);
  2215.         }    else {
  2216.         wantAll= TRUE;
  2217.         fAlnIndex->EachSelectedItemDo( AddSeqAtToList);
  2218.         }
  2219. }
  2220.             
  2221.  
  2222. pascal Integer TAlnDoc::SelectionToFile( Boolean AllatNoSelection,
  2223.             Str255        aFileName; integer seqFormat)  
  2224.             //return # written 
  2225. VAR
  2226.     longint        start, nbases;
  2227.     integer        nseqs;
  2228.     TSeqList        aSeqList;
  2229. {
  2230.     GetSelection( FALSE, allAtNoSelection, aSeqList, start, nbases);
  2231.     nseqs= aSeqList->GetSize();
  2232.     aSeqList->doWrite( aFileName, seqFormat); 
  2233.     aSeqList->Free();
  2234.     SelectionToFile= nseqs;
  2235. }
  2236.  
  2237.  
  2238.  
  2239. pascal void TAlnDoc::DoWrite(TFile aFile, Boolean makingCopy) // override 
  2240. VAR   outformat: integer;
  2241.     longint        start, nbases;
  2242.     integer        nseqs;
  2243.     TSeqList        aSeqList;
  2244.     Str63        aStr63;
  2245.     fi    : failInfo;
  2246.     
  2247.     pascal void HdlFailure(OSErr error, long message)
  2248.     {
  2249.         aSeqList= TSeqList(FreeIfObject(aSeqList));
  2250.         fSaveSelection= False;
  2251.     }
  2252.     
  2253. {
  2254.     aSeqList= NULL;
  2255.     aFile->GetName( aStr63); gOutputName= aStr63;
  2256.     if (fFormatPop == NULL) outformat= kGenBank
  2257.     else outformat= fFormatPop->GetCurrentItem(); 
  2258.     if ((fSaveSelection)) {
  2259.         fSaveSelection= False;
  2260.         CatchFailures( fi, HdlFailure);
  2261.         GetSelection( FALSE, True, aSeqList, start, nbases);
  2262.         aSeqList->doWriteRef( aFile->fDataRefNum, outformat);
  2263.         aSeqList= TSeqList(FreeIfObject( aSeqList));
  2264.         Success(fi);
  2265.         }    else {
  2266.         fSeqList->ClearSelections(); //! make sure we write all of seq from this call !?
  2267.         fSeqList->doWriteRef( aFile->fDataRefNum, outformat);
  2268.         }
  2269. }
  2270.  
  2271.  
  2272.  
  2273. pascal void TAlnDoc::DoEvent(EventNumber eventNumber, 
  2274.                                             TEventHandler        source; TEvent event) // override 
  2275. VAR
  2276.     procPtr        drawHook;
  2277.     hIcon    : Handle;
  2278. {
  2279.     switch (eventNumber) {
  2280.         case mLockButHit:
  2281.           if (fAlnView->fLocked) { 
  2282.                 fAlnView->fLocked= FALSE;
  2283.                 if (gConfiguration.hasColorQD) 
  2284.                     hIcon= Handle(GetCIcon( kUnLockIconID))
  2285.                 else 
  2286.                     hIcon= Handle(GetIcon( kUnLockIconID));
  2287.                 fLockButton->SetIcon( hIcon, kRedraw);
  2288.                 }            else {
  2289.                 fAlnView->fLocked= TRUE;
  2290.                 fAlnView->DeInstallEditSeq();
  2291.                 if (gConfiguration.hasColorQD) 
  2292.                     hIcon= Handle(GetCIcon( kLockIconID))
  2293.                 else 
  2294.                     hIcon= Handle(GetIcon( kLockIconID));
  2295.                 fLockButton->SetIcon( hIcon, kRedraw);    
  2296.                 }
  2297.             
  2298.         mColorButHit: {
  2299.              // fColorButton->HiliteState( TRUE, not fColorButton->fHilite);
  2300.           if (!fUseColor) { 
  2301.                 fUseColor= TRUE;
  2302.                 /*---
  2303.                 drawHook= &alnTEDrawHook;
  2304.                 TECustomHook(intDrawHook, drawHook, fAlnView->fEditSeq.fHTE);
  2305.                 ---*/
  2306.                 fAlnView->ForceRedraw();
  2307.                 }
  2308.             }
  2309.             
  2310.         mMonoButHit: {
  2311.              // fMonoButton->HiliteState( TRUE, not fMonoButton->fHilite);
  2312.           if (fUseColor) { 
  2313.                 fUseColor= FALSE;
  2314.                 /*---
  2315.                 drawHook= gDefTEDrawHook;
  2316.                 TECustomHook(intDrawHook, drawHook, fAlnView->fEditSeq.fHTE);
  2317.                 ---*/
  2318.                 fAlnView->ForceRedraw();
  2319.                 }
  2320.             }
  2321.                     
  2322.         otherwise
  2323.                 inherited::DoEvent( eventNumber, source, event);
  2324.         }
  2325. }
  2326.         
  2327.  
  2328.  
  2329. CONST
  2330.         kMaxOpenSeqed == 10;
  2331.  
  2332.  
  2333. pascal void TAlnDoc::AddSeqToList(TSequence item)  // override 
  2334. VAR last: integer;
  2335. {
  2336.  /*----
  2337.      inherited::AddSeqToList( item);  
  2338.     fAlnView->registerInsertLast( item);  
  2339.  ----*/
  2340.     fAlnView->addToAlnList( item);
  2341.     fAlnIndex->InsItemLast( 1);
  2342.     fAlnIndex->SelectItem( fAlnIndex->fNumOfRows, FALSE, TRUE, TRUE);
  2343.     //- fChangeCount= fChangeCount+1;
  2344.     this->Changed( 1, this);
  2345. }    
  2346.  
  2347.  
  2348.   
  2349. #pragma segment AOpen
  2350.  
  2351. pascal void TAlnDoc::OpenSeqedWindow(TSequence aSeq)
  2352. VAR
  2353.         TStdPrintHandler        aHandler;
  2354.         aSeqed    : TSeqedWindow;
  2355.         boolean        foundDoc;
  2356.         sname        : SeqName;
  2357.         
  2358.         pascal void checkOpenEdWinds( TWindow aWind)
  2359.         {
  2360.             if (Member(TObject(aWind), TSeqedWindow)) 
  2361.                 if (TSeqedWindow(aWind).fSequence == aSeq) {
  2362.                     aWind->Select(); foundDoc= TRUE;
  2363.                     }
  2364.         }
  2365. {
  2366.     foundDoc= FALSE;
  2367.     ForAllWindowsDo(checkOpenEdWinds);
  2368.     if (!foundDoc then begin
  2369.         aSeqed = TSeqedWindow(gViewServer->NewTemplateWindow(kSeqEdWindID, this));
  2370.         FailNIL(aSeqed);          
  2371.         aSeqed->ISeqedWindow(aSeq);
  2372.         sname= aSeq->fName;
  2373.         //- aSeqed->SetTitleForDoc( sname);
  2374.         aSeqed->SetTitle( concat(sname, ' Edit'));
  2375.         
  2376.         New(aHandler);  
  2377.         FailNIL(aHandler);
  2378.         aHandler->IStdPrintHandler(this,                     // its document 
  2379.                                     aSeqed->fSeqedView,                    // its view 
  2380.                                     !kSquareDots,            // does not have square dots 
  2381.                                     kFixedSize,                 // horzontal page size is fixed 
  2382.                                     !kFixedSize);            /* vertical page size is variable (could be
  2383.                                                                 set to TRUE on non-style TE systems) */
  2384.     
  2385.         aSeqed->ShowReverted(); 
  2386.         aSeqed->Open(); 
  2387.         aSeqed->Select();     
  2388.         }
  2389. }
  2390.  
  2391.  
  2392.  
  2393. pascal void TAlnDoc::OpenSeqs( boolean editOnly) 
  2394. VAR
  2395.     aCell    : GridCell;
  2396.     count    : integer;
  2397.     
  2398.     pascal void newEditWindow( integer anItem)
  2399.     TSequence        VAR aSeq;
  2400.     {
  2401.         aSeq= TSequence(this->fSeqList->At(anItem));
  2402.         if ((aSeq!=NULL) && (count<kMaxOpenSeqed)) {
  2403.             this->OpenSeqedWindow(aSeq);
  2404.             count= count+1;
  2405.             }
  2406.   }
  2407.     
  2408. {
  2409.     if ((fAlnIndex=NULL) || (fAlnIndex.firstSelectedItem == 0)) 
  2410.             //nada
  2411.             
  2412.     else if (editOnly 
  2413.         || (fAlnIndex.FirstSelectedItem == fAlnIndex->LastSelectedItem())) {
  2414.         count= 0;
  2415.         fAlnIndex->EachSelectedItemDo( newEditWindow);
  2416.         }
  2417.         
  2418. }
  2419.  
  2420.  
  2421.  
  2422.  
  2423.  
  2424. #pragma segment ARes //??
  2425.  
  2426. pascal void  TAlnDoc::DoMenuCommand(CommandNumber aCommandNumber) // override 
  2427. VAR
  2428.         aSeq        : TSequence;
  2429.         integer        menu, item, nSel;
  2430.         aName     : Str255;
  2431.         TAlnEditCommand        aAlnEditCommand ;
  2432.         TAlnPasteCommand        aAlnPasteCommand;
  2433.  
  2434.         longint        firstBase, nBases;
  2435.         TSeqList        aSeqList;
  2436.         TSeqTranslateCmd        aSeqTranslateCmd;
  2437.         TSeqReverseCmd        aSeqReverseCmd;
  2438.         TSeqRevComplCmd        aSeqRevComplCmd;
  2439.         TSeqComplementCmd        aSeqComplementCmd;
  2440.         TSeqCompressCmd        aSeqCompressCmd;
  2441.         TSeqDna2RnaCmd        aSeqDna2RnaCmd;
  2442.         TSeqRna2DnaCmd        aSeqRna2DnaCmd;
  2443.         TSeqLockIndelsCmd        aSeqLockIndelsCmd;
  2444.         TSeqUnlockIndelsCmd        aSeqUnlockIndelsCmd;
  2445.         
  2446.         
  2447.     pascal void doMakeConsensus(void)
  2448.     VAR 
  2449.             cons    : TSequence;
  2450.             TSeqList        aSeqList;
  2451.             longint        firstBase, nBases;
  2452.             arow, totalRows    : integer;
  2453.             VRect        vbounds;
  2454.     {        
  2455.         cons= fSeqList->Consensus();
  2456.         if ((cons!=NULL)) {
  2457.             aRow= fSeqList->GetIdentityItemNo( cons);
  2458.             totalRows= fSeqList->GetSize();
  2459.             fSeqList->Delete(cons);
  2460.             cons->Free();
  2461.             this->fAlnView->RowToVRect( aRow, totalRows-aRow+1, vbounds); 
  2462.             this->fAlnView->InvalidateVRect( vbounds);
  2463.             this->fAlnIndex->RowToVRect( aRow, totalRows-aRow+1, vbounds); 
  2464.             this->fAlnIndex->InvalidateVRect( vbounds);
  2465.             this->fAlnView->UpdateSize();   
  2466.             this->fAlnIndex->UpdateSize();
  2467.             }
  2468.             
  2469.         GetSelection( TRUE, TRUE, aSeqList, firstBase, nBases);
  2470.         aSeqList->MakeConsensus();
  2471.         cons= aSeqList->Consensus();
  2472.         aSeqList->Free();
  2473.         if ((cons!=NULL)) {
  2474.             AddSeqToList( cons);
  2475.             fAlnIndex->SelectItem( fSeqList.consensusRow, FALSE, TRUE, TRUE);
  2476.             fAlnIndex->ScrollSelectionIntoView(TRUE);
  2477.             }
  2478.     }
  2479.  
  2480.     
  2481.     pascal void MakeSeqPrint(Boolean doREMap)
  2482.     VAR
  2483.             TREMapDocument        aREMapDoc;
  2484.             aSeqPrDoc    : TSeqPrintDocument;
  2485.             longint        firstBase, nBases;
  2486.             aSeq        : TSequence;
  2487.     {
  2488.         FirstSelection( aSeq, firstBase, nBases);
  2489.         
  2490.         if (doREMap) {
  2491.             New(aREMapDoc);
  2492.             FailNIL(aREMapDoc);
  2493.             aREMapDoc->IREMapDocument(kPrintClipType, this, aSeq, firstBase, nbases);
  2494.             gSeqAppApplication->OpenNewDocument(aREMapDoc);  
  2495.             }        else {
  2496.             New(aSeqPrDoc);
  2497.             FailNIL(aSeqPrDoc);
  2498.             aSeqPrDoc->ISeqPrintDocument(kPrintClipType, this, aSeq, firstBase, nbases);
  2499.             gSeqAppApplication->OpenNewDocument(aSeqPrDoc);  
  2500.             }
  2501.     }
  2502.  
  2503.         
  2504.     pascal void MakeSeqSearch(integer command)
  2505.     VAR
  2506.             longint        firstBase, nBases, nList;
  2507.             aSeq        : TSequence;
  2508.             TSeqList        aSeqList;
  2509.     {        
  2510.         switch (command) {
  2511.             cGBBlast, 
  2512.             cGBFasta,
  2513.             cGeneidSearch,
  2514.             cBlocksSearch, 
  2515.             cGenmarkSearch: {
  2516.                 FirstSelection( aSeq, firstBase, nBases);
  2517.                 MailWithSeq( command, aSeq); 
  2518.                 }
  2519.                 
  2520.             cPythiaSearch,
  2521.             cGrailSearch: {
  2522.                 GetSelection( FALSE, TRUE, aSeqList, firstBase, nBases);
  2523.                 MailWithSeqList( command, aSeqList);  
  2524.                 aSeqList->Free();
  2525.                 }
  2526.             }
  2527.     }
  2528.  
  2529.     pascal void MakeAlnPrint(void)
  2530.     VAR  
  2531.             longint        start, nBases;
  2532.             aAlnPrDoc    : TAlnPrintDocument;
  2533.             aSeqList    : TSeqList;
  2534.     {
  2535.         GetSelection( TRUE, TRUE, aSeqList, start, nBases);
  2536.         if ((aSeqList.GetSize>1)) {
  2537.             New(aAlnPrDoc);
  2538.             FailNIL(aAlnPrDoc);
  2539.             aAlnPrDoc->IAlnPrintDocument(kPrintClipType, this, aSeqList, start, nBases);
  2540.             gSeqAppApplication->OpenNewDocument(aAlnPrDoc); //finish up
  2541.             //?? aSeqList->Free(); << NO, aAlnPrDoc owns this list !
  2542.             }        else {
  2543.           aSeqList->Free(); //drop only list
  2544.             MakeSeqPrint( FALSE);
  2545.             }
  2546.     }
  2547.     
  2548.     pascal void MakeDottyPlot(void)
  2549.     VAR  
  2550.             longint        start, nBases;
  2551.             aSeqList    : TSeqList;
  2552.             aDottyPlotDoc    : TDottyPlotDocument;
  2553.     {
  2554.         GetSelection( FALSE, TRUE, aSeqList, start, nBases);
  2555.         if ((aSeqList.GetSize>0)) {
  2556.             New(aDottyPlotDoc);
  2557.             FailNIL(aDottyPlotDoc);
  2558.             aDottyPlotDoc->IDottyPlotDocument(kPrintClipType, this, aSeqList, start, nBases);
  2559.             gSeqAppApplication->OpenNewDocument(aDottyPlotDoc); //finish up
  2560.             //! Don't FREE aSeqList -- DottyPlotDoc took over ownership 
  2561.             }
  2562.     }
  2563.     
  2564.     pascal void CallChildApp(theMenuName:Str255);
  2565.     VAR
  2566.         TSeqList        aSeqList;
  2567.         longint        start, nbases;
  2568.         
  2569.         pascal Boolean isTheCommand( TChildCommand aChildCommand)
  2570.         {
  2571.             if ((aChildCommand->fMenuName == theMenuName)) {
  2572.                 aChildCommand->LaunchDialog( aSeqList);
  2573.                 isTheCommand= TRUE;
  2574.                 }            else
  2575.                 isTheCommand= FALSE;
  2576.         }
  2577.         
  2578.     {
  2579.         GetSelection( TRUE, TRUE, aSeqList, start, nBases);
  2580.         if (gChildCommandList->FirstThat( isTheCommand) != NULL) ;
  2581.         aSeqList->Free();
  2582.     }
  2583.  
  2584.     pascal void    SelectSequence( integer anItem)
  2585.     {
  2586.         fAlnIndex->SelectItem( anItem, kExtend, kHighlight, kSelect);
  2587.     }
  2588.                 
  2589.     pascal void    DoSeqChangeCommand( TSeqChangeCmd aCommand)
  2590.     VAR        aSeqList: TSeqList; 
  2591.                 Longint        firstBase, nBases;
  2592.     {
  2593.         FailNIL(aCommand);
  2594.         GetSelection( TRUE, TRUE, aSeqList, firstBase, nBases);
  2595.         aCommand->ISeqChangeCmd( this, fAlnView, aSeqList); 
  2596.         PostCommand( aCommand);
  2597.     }
  2598.     
  2599.     
  2600. {
  2601.     CommandToMenuItem(aCommandNumber, menu, item);
  2602.     if (menu == mChildren) {
  2603.         switch (aCommandNumber) {
  2604.             cAddChildCmd,
  2605.             case cRemoveChildCmd:  
  2606.                 inherited::DoMenuCommand(aCommandNumber);
  2607.             Otherwise {
  2608.                         GetItem(GetMHandle(menu), item, aName);
  2609.                         CallChildApp( aName);
  2610.                         }
  2611.             }
  2612.         }        
  2613.     else CASE aCommandNumber OF
  2614.  
  2615.         cSaveSelection: {
  2616.             fSaveSelection= True;
  2617.             inherited::DoMenuCommand(cSaveCopy);
  2618.             }
  2619.             
  2620.         cSelectAll:  fAlnIndex->AllItemsDo( SelectSequence);
  2621.  
  2622.         cCut, cCopy, cClear: {
  2623.                 NEW(aAlnEditCommand);
  2624.                 FailNIL(aAlnEditCommand);
  2625.                 aAlnEditCommand->IAlnEditCommand(this, aCommandNumber);
  2626.                 PostCommand( aAlnEditCommand);
  2627.                 }
  2628.  
  2629.         case cPaste:
  2630.                 if (gClipboardMgr->fClipView->ContainsClipType(kAlnScrapType)) {
  2631.                     NEW(aAlnPasteCommand);
  2632.                     FailNIL(aAlnPasteCommand);
  2633.                     aAlnPasteCommand->IAlnPasteCommand(this);
  2634.                     PostCommand(  aAlnPasteCommand);
  2635.                     }                /* else if (gClipView->ContainsClipType('TEXT')) {
  2636.                     // convert from TEXT to sequence data...
  2637.                     }                */
  2638.                 else  
  2639.                     inherited::DoMenuCommand(aCommandNumber);
  2640.     
  2641.         
  2642.         cNewSeq        : {
  2643.                 AddNewSeqToList();
  2644.                 OpenSeqs(kEditOnly); 
  2645.                 }
  2646.                         
  2647.         cEditSeq        : OpenSeqs(kEditOnly);
  2648.  
  2649.         cConsensus    : doMakeConsensus;
  2650.  
  2651.         cTranslateSeq: {
  2652.                 New(aSeqTranslateCmd);
  2653.                 DoSeqChangeCommand( aSeqTranslateCmd);
  2654.                 }
  2655.         cReverseSeq: {
  2656.                 New(aSeqReverseCmd);
  2657.                 DoSeqChangeCommand( aSeqReverseCmd);
  2658.                 }
  2659.         cComplementSeq: {
  2660.                 New(aSeqComplementCmd);
  2661.                 DoSeqChangeCommand( aSeqComplementCmd);
  2662.                 }
  2663.         cRevComplement: {
  2664.                 New(aSeqRevComplCmd);
  2665.                 DoSeqChangeCommand( aSeqRevComplCmd);
  2666.                 }
  2667.         cCompress: {
  2668.                 New(aSeqCompressCmd);
  2669.                 DoSeqChangeCommand( aSeqCompressCmd);
  2670.                 }
  2671.         cLockIndels: {
  2672.                 New(aSeqLockIndelsCmd);
  2673.                 DoSeqChangeCommand( aSeqLockIndelsCmd);
  2674.                 }
  2675.         cUnlockIndels: {
  2676.                 New(aSeqUnlockIndelsCmd);
  2677.                 DoSeqChangeCommand( aSeqUnlockIndelsCmd);
  2678.                 }
  2679.         cDna2Rna: {
  2680.                 New(aSeqDna2RnaCmd);
  2681.                 DoSeqChangeCommand( aSeqDna2RnaCmd);
  2682.                 }
  2683.         cRna2Dna: {
  2684.                 New(aSeqRna2DnaCmd);
  2685.                 DoSeqChangeCommand( aSeqRna2DnaCmd);
  2686.                 }
  2687.         
  2688.         MakeAlnPrint        cPrettyPrint;
  2689.         cRestrictMap: MakeSeqPrint( TRUE); 
  2690.         cDottyPlot    : MakeDottyPlot;
  2691.       
  2692.         cGeneidSearch,
  2693.         cBlocksSearch,
  2694.         cGenmarkSearch,
  2695.         cGrailSearch,
  2696.         cPythiaSearch,
  2697.         cGBBlast,
  2698.         cGBSearch    :    MakeSeqSearch(aCommandNumber);
  2699.         
  2700.         default:
  2701.             inherited::DoMenuCommand(aCommandNumber);
  2702.         }
  2703. }
  2704.  
  2705.  
  2706. #pragma segment ARes  
  2707.  
  2708.  
  2709. pascal void TAlnDoc::DoSetupMenus(void) // override 
  2710. VAR 
  2711.     nsel    : integer;
  2712.     MenuHandle        childMenuHandle;
  2713.     indexSelection, haveSel    : Boolean;
  2714.     
  2715.     pascal void EnableChildMenus( TChildCommand aChildCommand)
  2716.     {
  2717.         aChildCommand->EnableMenu( childMenuHandle, nsel) ;
  2718.     }
  2719.     
  2720. {
  2721.   inherited::DoSetupMenus();    
  2722.     
  2723.     nsel= 0;
  2724.     if ((fAlnView!=NULL) && (fAlnView.FirstSelectedCell.v > 0)) 
  2725.         nsel= 1 + fAlnView.LastSelectedCell.v - fAlnView.FirstSelectedCell.v;
  2726.     indexSelection= ((fAlnIndex!=NULL) && (fAlnIndex.FirstSelectedItem>0));
  2727.     if (indexSelection && (nSel=0)) 
  2728.         nsel= 1 + fAlnIndex.LastSelectedItem - fAlnIndex->FirstSelectedItem();
  2729.     haveSel= nsel>=1;
  2730.     
  2731.     /*----
  2732.     if (indexSelection) {
  2733.         SetEditCmdName(cCut, cCutSeq);
  2734.         SetEditCmdName(cCopy, cCopySeq);
  2735.         SetEditCmdName(cClear, cClearSeq);
  2736.         }
  2737.     else if ((fAlnView->fEditRow!=0)) {
  2738.         SetEditCmdName(cCut, cCutText);
  2739.         SetEditCmdName(cCopy, cCopyText);
  2740.         SetEditCmdName(cClear, cClearText);
  2741.         }
  2742.     ----*/
  2743.     //if (indexSelection && clipHasSeqText...) CanPaste('TEXT'); 
  2744.     //if (indexSelection) */ /*!? Paste at end if no selection 
  2745.     gClipboardMgr->CanPaste(kAlnScrapType);
  2746.     
  2747.     Enable(cSaveSelection, haveSel); 
  2748.  
  2749.     Enable(cCut, indexSelection);
  2750.     Enable(cCopy, indexSelection);
  2751.     Enable(cClear, indexSelection);
  2752.     Enable(cSelectAll, TRUE);
  2753.  
  2754.     Enable( cNewSeq, TRUE);
  2755.     Enable( cEditSeq, haveSel); 
  2756.     Enable( cPrettyPrint, haveSel); 
  2757.     Enable( cDottyPlot, haveSel); 
  2758.     Enable( cConsensus, nsel>=2); 
  2759.     
  2760.     Enable( cGBSearch, gGoodMac && gTCPIsInstalled && (haveSel)); 
  2761.     Enable( cGBBlast, gGoodMac && gTCPIsInstalled && (haveSel)); 
  2762.     Enable( cGeneidSearch, gGoodMac && gTCPIsInstalled && (haveSel)); 
  2763.     Enable( cBlocksSearch, gGoodMac && gTCPIsInstalled && (haveSel)); 
  2764.     Enable( cGenmarkSearch, gGoodMac && gTCPIsInstalled && (haveSel)); 
  2765.     Enable( cGrailSearch, gGoodMac && gTCPIsInstalled && (haveSel)); 
  2766.     Enable( cPythiaSearch, gGoodMac && gTCPIsInstalled && (haveSel)); 
  2767.  
  2768.     Enable( cReverseSeq, haveSel); 
  2769.     Enable( cComplementSeq, haveSel); 
  2770.     Enable( cRevComplement, haveSel); 
  2771.     Enable( cCompress, haveSel); 
  2772.     Enable( cLockIndels, haveSel); 
  2773.     Enable( cUnlockIndels, haveSel); 
  2774.     Enable( cDna2Rna, haveSel/*&fKind=Dna or Nuc*/); 
  2775.     Enable( cRna2Dna, haveSel/*&fKind=Rna or Nuc*/); 
  2776.     Enable( cTranslateSeq, haveSel); 
  2777.     
  2778.     Enable( cRestrictMap, haveSel); 
  2779.     
  2780.     if ((gChildCommandList!=NULL)) {
  2781.         childMenuHandle = GetMHandle(mChildren);
  2782.         gChildCommandList->Each( enableChildMenus);
  2783.         }
  2784. }
  2785.  
  2786.  
  2787.  
  2788.  
  2789.  
  2790.  
  2791.  
  2792. //    TAlnEditCommand -----------------------    
  2793. #pragma segment TAlnEditCommand
  2794.  
  2795. pascal void TAlnEditCommand::IAlnEditCommand(TAlnDoc itsDocument, short itsCommand)
  2796.     FailInfo        VAR fi;
  2797.     TCommandHandler        theContext; 
  2798.  
  2799.     pascal void HdlAllocationFailure(OSErr error, long message)
  2800.     {
  2801.         Free();
  2802.     }
  2803.  
  2804. {
  2805.     fSelection= NULL;
  2806.     fOldList= NULL;
  2807.     FailNIL( itsDocument);
  2808.     // theContext:    TCommandHandler;
  2809.     theContext= itsDocument->fAlnView->GetContext(itsCommand);
  2810.     ICommand(itsCommand, theContext, kCanUndo, kCausesChange, theContext);
  2811.  
  2812.     fAlnDoc = itsDocument;
  2813.     CatchFailures(fi, HdlAllocationFailure);
  2814.     fSelection = MakeNewRgn;                     
  2815.     fOldList= TSeqList(fAlnDoc->fSeqList->Clone());
  2816.     FailNIL( fOldList);
  2817.     Success(fi);
  2818.     CopyRgn(fAlnDoc->fAlnIndex.fSelections, fSelection);
  2819.     
  2820.     fChangesClipboard = itsCommand != cClear;
  2821.     fCausesChange = itsCommand != cCopy;
  2822.     fCanUndo = itsCommand != cCopy;  //?
  2823. }
  2824.  
  2825.  
  2826. pascal void TAlnEditCommand::Free(void) // override 
  2827. {
  2828.     if ((fSelection!=NULL)) DisposeRgn(fSelection);
  2829.     fSelection = NULL;
  2830.     if ((fOldList!=NULL)) fOldList->Free();
  2831.     fOldList= NULL;
  2832.     inherited::Free();
  2833. }
  2834.  
  2835.  
  2836. pascal void TAlnEditCommand::CopySelection(void)
  2837. VAR
  2838.         TAlnDoc        clipAlnDoc;
  2839.         clipView    : TAlnView;
  2840.         
  2841.     pascal void CopyRowToClipboard(integer aRow)
  2842.     TSequence        VAR  aSeq;
  2843.     {
  2844.         aSeq = TSequence(fAlnDoc->fSeqList->SeqAt(aRow).Clone);
  2845.         clipAlnDoc->fSeqList->InsertLast( aSeq);
  2846.     }
  2847.  
  2848. {
  2849.     New(clipAlnDoc);
  2850.     FailNIL(clipAlnDoc);
  2851.     clipAlnDoc->IAlnDoc(NULL);   //< IAlnDoc creates AlnDoc->fSeqList && adds 1 blank new seq...
  2852.     clipAlnDoc->FreeData();    /* drop blank seq*/    
  2853.     clipAlnDoc->DoInitialState();  //?
  2854.     
  2855.     fAlnDoc->fAlnIndex->EachSelectedItemDo(CopyRowToClipboard); 
  2856.  
  2857.     clipView= TAlnView( gViewServer->DoCreateViews(clipAlnDoc, NULL, kAlnViewID, gZeroVPt));
  2858.     FailNIL( clipView);
  2859.  
  2860.             // from TAlnView.IAlnView....
  2861.     clipView->fAlnDoc= clipAlnDoc;
  2862.     clipView->fAlnList= clipAlnDoc->fSeqList;
  2863.     clipView->fEditSeq= NULL;
  2864.     clipView->fEditRow= 0;
  2865.     clipView->fRowheight= clipView->GetRowHeight(1); 
  2866.     clipAlnDoc->fAlnView= clipView;
  2867.  
  2868.             // from TAlnDoc.ShowReverted...
  2869.     clipView->DelRowLast( clipView->fNumOfRows);
  2870.     clipView->InsRowLast( clipAlnDoc->fSeqList->GetSize(), clipView->fRowHeight);  
  2871.     clipView->UpdateAllWidths(); 
  2872.  
  2873.     this->ClaimClipboard(clipView);  
  2874.     //- clipView->AdjustFrame(); ??
  2875. }
  2876.  
  2877.  
  2878.  
  2879. pascal void TAlnEditCommand::DeleteSelection(void)
  2880. VAR
  2881.         integer        totalRows;
  2882.         
  2883.     pascal void MarkDelete(integer aRow)
  2884.     VAR     aSeq    : TSequence;
  2885.              VRect        vbounds;
  2886.     {
  2887.         aSeq= fAlnDoc->fSeqList->SeqAt(aRow);
  2888.         if ((aSeq!=NULL)) {
  2889.             aSeq->fDeleted= TRUE;
  2890.             //- fAlnDoc->fSeqList->AtDelete(aRow);*/ /* this should be safe !!! NO !in Mapp3 (or 2)!!!...
  2891.             
  2892.             fAlnDoc->fAlnView->RowToVRect( aRow, totalRows-aRow+1, vbounds); 
  2893.             fAlnDoc->fAlnView->InvalidateVRect( vbounds);
  2894.             
  2895.             fAlnDoc->fAlnIndex->RowToVRect( aRow, totalRows-aRow+1, vbounds); 
  2896.             fAlnDoc->fAlnIndex->InvalidateVRect( vbounds);
  2897.             fAlnDoc->fAlnIndex->SelectItem( aRow, kDontExtend, kDontHighlight, !kSelect);
  2898.             }
  2899.     }
  2900.  
  2901.     pascal void ReallyDeleteMarked( TSequence aSeq)
  2902.     {
  2903.         if (aSeq->fDeleted)) fAlnDoc->fSeqList->Delete( aSeq);
  2904.     }
  2905.  
  2906. {
  2907.     totalRows= fOldList->GetSize();
  2908.     fAlnDoc->fAlnIndex->EachSelectedItemDo(MarkDelete);
  2909.     fAlnDoc->fSeqList->Each(ReallyDeleteMarked);
  2910.     fAlnDoc->fAlnView->UpdateSize();  //must do before Index.update... combine these
  2911.     fAlnDoc->fAlnIndex->UpdateSize();
  2912. }
  2913.  
  2914.  
  2915. pascal void TAlnEditCommand::RestoreSelection(void)
  2916. VAR  aRow, totalRows: integer;
  2917.     
  2918.     pascal void restoreDeletes(TSequence aSeq)
  2919.     VRect        VAR  vbounds;
  2920.     {
  2921.         aRow= aRow+1;
  2922.         if ((aSeq->fDeleted)) {  
  2923.             aSeq->fDeleted= FALSE;
  2924.             fAlnDoc->fSeqList->InsertBefore(aRow, aSeq);     
  2925.             
  2926.             fAlnDoc->fAlnView->InsRowBefore( aRow, 1, fAlnDoc->fAlnView.fRowHeight);
  2927.             /*- // insrow does this
  2928.             fAlnDoc->fAlnView->RowToVRect( aRow, totalRows-aRow+1, vbounds); 
  2929.             fAlnDoc->fAlnView->InvalidateVRect( vbounds);
  2930.             ---*/
  2931.  
  2932.             fAlnDoc->fAlnIndex->InsRowBefore( aRow, 1, fAlnDoc->fAlnView.fRowHeight);
  2933.             //- fAlnDoc->fAlnIndex->SelectItem( aRow, kExtend, kHighlight, kSelect);
  2934.             /*- // insrow does this
  2935.             fAlnDoc->fAlnIndex->RowToVRect( aRow, totalRows-aRow+1, vbounds); 
  2936.             fAlnDoc->fAlnIndex->InvalidateVRect( vbounds);
  2937.             ---*/
  2938.             }
  2939.     }
  2940.  
  2941. {
  2942.     aRow= 0;
  2943.     totalRows= fOldList->GetSize();
  2944.     fOldList->Each( restoreDeletes);
  2945.     fAlnDoc->fAlnView->UpdateSize();  //must do before Index.update... combine these
  2946.     fAlnDoc->fAlnIndex->UpdateSize();  
  2947.     ReSelect(); // == fAlnDoc->fAlnIndex->ReSelect(fSelection);
  2948. }
  2949.  
  2950.  
  2951. pascal void TAlnEditCommand::Commit(void)
  2952.     pascal void commitDeletes(TSequence aSeq)
  2953.     {
  2954.         if ((aSeq!=NULL) && (aSeq->fDeleted)) aSeq->Free();  
  2955.     }
  2956. {
  2957.     fOldList->Each( commitDeletes);
  2958.     this->DoNotification();
  2959. }
  2960.  
  2961.  
  2962. pascal void TAlnEditCommand::ReSelect(void)
  2963. {
  2964.     fAlnDoc->fAlnIndex->ReSelect(fSelection);
  2965. }
  2966.  
  2967.  
  2968. pascal void TAlnEditCommand::DoIt(void)
  2969. {
  2970.     if (fIdentifier != cClear) CopySelection;
  2971.     if (fIdentifier != cCopy) DeleteSelection;
  2972.     fCommandDone= True; 
  2973. }
  2974.  
  2975.  
  2976. pascal void TAlnEditCommand::UndoIt(void)
  2977. /* If the user has changed the selection since this command was created,
  2978.   restore it before Undoing so that the correct cells are affected. */
  2979. {
  2980.     if (fIdentifier != cCopy) {
  2981.         RestoreSelection();
  2982.         //- ReSelect;    << see RestoreSelection....
  2983.         fAlnDoc->fAlnView->ScrollSelectionIntoView(TRUE);
  2984.         fCommandDone= false; 
  2985.         }
  2986. }
  2987.  
  2988.  
  2989. pascal void TAlnEditCommand::RedoIt(void)
  2990. /* If the user has changed the selection since this command was created,
  2991.   restore it before Redoing so that the correct cells are affected. */
  2992. {
  2993.     if (fIdentifier != cCopy) {
  2994.         DeleteSelection();
  2995.         /*- ReSelect;     ! !After DELETION....*/     
  2996.         fAlnDoc->fAlnView->ScrollSelectionIntoView(TRUE);
  2997.         fCommandDone= true; 
  2998.         }
  2999. }
  3000.  
  3001.  
  3002.  
  3003.  
  3004.  
  3005.  
  3006.  
  3007.  
  3008.  
  3009.  
  3010. // TAlnPasteCommand -----------------  
  3011. #pragma segment TAlnPasteCommand
  3012.  
  3013.  
  3014. pascal void TAlnPasteCommand::IAlnPasteCommand(TAlnDoc itsDocument)
  3015. VAR     fi:            FailInfo;
  3016.         TCommandHandler        theContext; 
  3017.  
  3018.     pascal void HdlAllocationFailure(OSErr error, long message)        
  3019.     {
  3020.         Free();
  3021.     }
  3022.  
  3023.     pascal void cloneit( TSequence aSeq)
  3024.     integer        VAR  aRow;
  3025.     {
  3026.         aRow= fClipList->GetEqualItemNo(aSeq);
  3027.         aSeq= TSequence(aSeq->Clone());
  3028.         fClipList->AtPut( aRow, aSeq);
  3029.     }
  3030.  
  3031. {
  3032.     // theContext:    TCommandHandler;
  3033.     theContext= itsDocument->fAlnView->GetContext(cPaste);
  3034.     ICommand(cPaste, theContext, kCanUndo, kCausesChange, theContext);
  3035.  
  3036.     fAlnDoc = itsDocument;
  3037.     CatchFailures(fi, HdlAllocationFailure);
  3038.     fSelection = MakeNewRgn;                            // copy the current selection region 
  3039.     Success(fi);
  3040.     CopyRgn(fAlnDoc->fAlnIndex.fSelections, fSelection);
  3041.     //- fClipDocument= TAlnView(gClipView).fAlnDoc;
  3042.         /*^^ used cloned clip list of seqs only, private store so other commands don't
  3043.             mysteriously mangle our command before commit...
  3044.             --- still mangling before commit -- do away w/ clone cliplist,
  3045.             && clone on doit, free on undo...
  3046.         */
  3047.     fClipList= TSeqList(TAlnView(gClipboardMgr->fClipView).fAlnList->Clone());
  3048.     fClipList->Each( cloneit);
  3049.  
  3050.     fInsRow= fAlnDoc->fAlnIndex->LastSelectedItem();
  3051.     if (fInsRow=0) fInsRow= fAlnDoc->fSeqList->GetSize();
  3052.     
  3053.     fReplacedSeqs= TSeqList(NewList);
  3054.     FailNIL(fReplacedSeqs);
  3055. }
  3056.  
  3057.  
  3058. pascal void TAlnPasteCommand::Free(void) // override 
  3059. {
  3060.     if (fSelection != NULL) DisposeRgn(fSelection);
  3061.     fSelection = NULL;
  3062.     TObject(fClipList) = FreeListIfObject(fClipList); //New since cloned clip list
  3063.     TObject(fReplacedSeqs) = FreeListIfObject(fReplacedSeqs);
  3064.     inherited::Free();
  3065. }
  3066.  
  3067.  
  3068. pascal void TAlnPasteCommand::DoIt(void)
  3069. VAR  aRow, totalRows: integer;
  3070.         
  3071.     pascal void InsertMarker( TSequence aSeq)
  3072.     VRect        VAR   vbounds;
  3073.     {
  3074.         aRow= aRow+1;
  3075.         // mark here, fDeleted, then clone in .Commit method
  3076.         aSeq= TSequence(aSeq->Clone()); //!NEW: prevent mangle by other cmds
  3077.         aSeq->fDeleted= TRUE;  //< this is mark that we Inserted it (not deleted)
  3078.  
  3079.         fAlnDoc->fSeqList->InsertBefore( aRow, aSeq);
  3080.         
  3081.         fAlnDoc->fAlnView->InsRowBefore( aRow, 1, fAlnDoc->fAlnView.fRowHeight);
  3082.         /*-- // insrow does this
  3083.         fAlnDoc->fAlnView->RowToVRect( aRow, totalRows-aRow+1, vbounds); 
  3084.         fAlnDoc->fAlnView->InvalidateVRect( vbounds);
  3085.         ---*/
  3086.  
  3087.         fAlnDoc->fAlnIndex->InsRowBefore( aRow, 1, fAlnDoc->fAlnView.fRowHeight);
  3088.         /*-- // insrow does this
  3089.         fAlnDoc->fAlnIndex->RowToVRect( aRow, totalRows-aRow+1, vbounds); 
  3090.         fAlnDoc->fAlnIndex->InvalidateVRect( vbounds);
  3091.         ---*/
  3092.     }
  3093.  
  3094. {        
  3095.     aRow= fInsRow;
  3096.     /*---
  3097.     totalRows= fAlnDoc->fSeqList.GetSize + fClipDocument->fSeqList->GetSize();
  3098.     fClipDocument->fSeqList->Each(InsertMarker);
  3099.     ---*/
  3100.     totalRows= fAlnDoc->fSeqList.GetSize + fClipList->GetSize();
  3101.     fClipList->Each(InsertMarker);
  3102.     fAlnDoc->fAlnView->UpdateAllWidths();
  3103.     fAlnDoc->fAlnView->UpdateSize();  //must do before Index.update... combine these
  3104.     fAlnDoc->fAlnIndex->UpdateSize();  
  3105.     fCommandDone= True; 
  3106.  
  3107.  
  3108. pascal void TAlnPasteCommand::UndoIt(void)
  3109. VAR
  3110.         integer        totalRows;
  3111.         
  3112.     pascal void DeleteIfMarked(TSequence aSeq)
  3113.     VAR     vbounds: VRect;
  3114.              integer        aRow;
  3115.     {
  3116.         if ((aSeq!=NULL) && (aSeq->fDeleted)) {
  3117.             aSeq->fDeleted= FALSE;
  3118.             aRow= fAlnDoc->fSeqList->GetEqualItemNo( aSeq);
  3119.             fAlnDoc->fSeqList->AtDelete(aRow); // is this safe? -- we are in SeqList.Each...
  3120.             aSeq->Free(); //!NEW: prevent mangled command 
  3121.             
  3122.             fAlnDoc->fAlnView->RowToVRect( aRow, totalRows-aRow+1, vbounds); 
  3123.             fAlnDoc->fAlnView->InvalidateVRect( vbounds);
  3124.             
  3125.             fAlnDoc->fAlnIndex->RowToVRect( aRow, totalRows-aRow+1, vbounds); 
  3126.             fAlnDoc->fAlnIndex->InvalidateVRect( vbounds);
  3127.             fAlnDoc->fAlnIndex->SelectItem( aRow, kDontExtend, kDontHighlight, !kSelect);
  3128.             }
  3129.     }
  3130.  
  3131. {
  3132.     totalRows= fAlnDoc->fSeqList->GetSize();
  3133.     fAlnDoc->fSeqList->Each( DeleteIfMarked);
  3134.     fAlnDoc->fAlnView->UpdateAllWidths();
  3135.     fAlnDoc->fAlnView->UpdateSize();  //must do before Index.update... combine these
  3136.     fAlnDoc->fAlnIndex->UpdateSize();
  3137.     fCommandDone= false; 
  3138. }
  3139.  
  3140.  
  3141. pascal void TAlnPasteCommand::RedoIt(void)
  3142. {
  3143.     DoIt();
  3144.     fCommandDone= True; 
  3145. }
  3146.  
  3147. pascal void TAlnPasteCommand::Commit(void) // override 
  3148.  
  3149.     pascal void commitInserts(TSequence aSeq)
  3150.     integer        VAR  aRow;
  3151.     {
  3152.         if ((aSeq->fDeleted)) {
  3153.             aSeq->fDeleted= FALSE;
  3154.             /*---   !NEW: no more: too much hassle
  3155.             aRow= fAlnDoc->fSeqList->GetEqualItemNo( aSeq);
  3156.             aSeq= TSequence(aSeq->Clone());
  3157.             fAlnDoc->fSeqList->AtPut( aRow, aSeq);
  3158.             ---*/
  3159.             }
  3160.     }
  3161. {
  3162.     fAlnDoc->fSeqList->Each( commitInserts);
  3163.     this->DoNotification();
  3164. }
  3165.  
  3166. pascal void TAlnPasteCommand::UpdateViews(void)
  3167. {
  3168.  
  3169. }
  3170.  
  3171.